Skip to content

refactor entry#364

Closed
mhx wants to merge 237 commits into
mainfrom
mhx/refactor-entry
Closed

refactor entry#364
mhx wants to merge 237 commits into
mainfrom
mhx/refactor-entry

Conversation

@mhx

@mhx mhx commented Apr 23, 2026

Copy link
Copy Markdown
Owner

No description provided.

mhx added 30 commits April 20, 2026 11:32
The original implementation unnecessarily created a new vector of strings
and performed an extra hash lookup for each entry. The new version just
sorts entry iterators directly, avoiding both the string allocation and
the extra lookup.
The original implementation was unnecessarily complex. Instead of using
two vectors and sorting one of them, we can simply scatter the values
directly into the output vector. In debug mode, a second bit-vector
ensures that we're not passing in a broken index.
mhx added 26 commits April 21, 2026 23:34
@mhx mhx requested a review from Copilot April 23, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors writer “entry/inode” plumbing toward handle/view-based APIs, modernizes algorithms to C++20 ranges, and introduces new packed/container utilities.

Changes:

  • Replaces legacy writer entry/inode types with entry_id/inode_id + handle/view abstractions and adjusts dependent writer components.
  • Migrates many algorithms/tests from <algorithm> iterator pairs to std::ranges::*.
  • Adds new internal utilities (packed/container types, event tracer, map utilities) and updates build/test targets accordingly.

Reviewed changes

Copilot reviewed 128 out of 172 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/writer/internal/global_entry_data.cpp Reworks global entry indexing and adds memory-usage dumping utilities.
include/dwarfs/writer/internal/global_entry_data.h Changes global entry data maps to indexed maps and introduces string_view-keyed tables.
include/dwarfs/internal/synchronized.h Extends synchronized wrapper with load/release/store and a no_mutex policy.
include/dwarfs/writer/entry_interface.h Shrinks the public entry_interface API surface.
src/malloc_byte_buffer.cpp Changes frozen-buffer semantics for clear() and updates comments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +53 to 71
void sort_and_index_map(T& map) {
using index_type = T::mapped_type;
using iterator = T::iterator;

std::vector<iterator> order;
order.reserve(map.size());

for (auto it = map.begin(); it != map.end(); ++it) {
order.push_back(it);
}

std::ranges::sort(order, std::ranges::less{}, &T::value_type::first);

index_type ix{0};

for (iterator it : order) {
it->second = ix++;
}
}

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order stores map iterators, but the std::ranges::sort projection &T::value_type::first is applied to the iterator itself, not to *it. This will not compile (or will be ill-formed) because the iterator type has no first member. Use a projection/lambda that returns the key from the iterator (e.g., [](iterator it){ return it->first; }) or store pointers/refs to value_type instead of iterators.

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +111
using string_view_keyed_map_type =
map_type<std::string_view, T, string_like_hash, std::equal_to<>>;

using string_view_index_map_type = string_view_keyed_map_type<index_type>;

index_map_type<uid_type> uids_;
index_map_type<gid_type> gids_;
index_map_type<mode_type> modes_;
string_view_index_map_type names_;
string_view_index_map_type symlinks_;

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names_/symlinks_ now store keys as std::string_view, but this class does not own backing storage for those views. If callers pass views into temporary or short-lived strings, the map will retain dangling references and exhibit use-after-free bugs. Prefer owning keys (std::string with transparent hash/equal) or explicitly intern/store the strings in a stable arena owned by global_entry_data and store views into that arena.

Suggested change
using string_view_keyed_map_type =
map_type<std::string_view, T, string_like_hash, std::equal_to<>>;
using string_view_index_map_type = string_view_keyed_map_type<index_type>;
index_map_type<uid_type> uids_;
index_map_type<gid_type> gids_;
index_map_type<mode_type> modes_;
string_view_index_map_type names_;
string_view_index_map_type symlinks_;
using string_keyed_map_type =
map_type<std::string, T, string_like_hash, std::equal_to<>>;
using string_index_map_type = string_keyed_map_type<index_type>;
index_map_type<uid_type> uids_;
index_map_type<gid_type> gids_;
index_map_type<mode_type> modes_;
string_index_map_type names_;
string_index_map_type symlinks_;

Copilot uses AI. Check for mistakes.
value_type value;
{
write_lock_type lock(mx_);
value.swap(value_);

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release() assumes value_type has a member swap(); that is not guaranteed for arbitrary T and will fail to compile for types that only support ADL swap or are merely movable. Use using std::swap; swap(value, value_); (or std::exchange(value_, value_type{}) if default-constructible) to make this generic.

Suggested change
value.swap(value_);
using std::swap;
swap(value, value_);

Copilot uses AI. Check for mistakes.
Comment on lines +30 to 36
class entry_interface {
public:
virtual std::string path_as_string() const = 0;
virtual std::string unix_dpath() const = 0;
virtual std::string const& name() const = 0;
virtual file_size_t size() const = 0;
virtual file_size_t allocated_size() const = 0;
virtual ~entry_interface() = default;

virtual bool is_directory() const = 0;
virtual std::string unix_dpath() const = 0;
};

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes several previously-declared virtual methods (e.g., path_as_string(), name(), size(), allocated_size()) from a public header, which is an ABI/API breaking change for any downstream implementations/users of entry_interface. If the intent is to narrow the interface, consider either (1) introducing a new interface type and deprecating the old one, or (2) keeping the old methods with defaulted/redirected implementations until a major-version bump.

Copilot uses AI. Check for mistakes.

void clear() override {
assert_not_frozen("clear");
// clear *only* resets the size and does affect the allocated memory

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is missing a negation and currently reads as the opposite of the likely intent. It should say that clear does not affect the allocated memory.

Suggested change
// clear *only* resets the size and does affect the allocated memory
// clear *only* resets the size and does not affect the allocated memory

Copilot uses AI. Check for mistakes.
@sonarqubecloud

sonarqubecloud Bot commented Apr 23, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@mhx mhx closed this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants