Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/pup/core/string_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace pup {
enum class StringId : std::uint32_t { Empty = 0 };

/// Check if StringId represents the empty string
/// Only the empty string interns to Empty, so a guard may test the handle instead (#391).
[[nodiscard]]
constexpr auto is_empty(StringId id) -> bool
{
Expand Down
12 changes: 0 additions & 12 deletions src/cli/cmd_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,22 +1287,10 @@ auto merge_out_of_scope_commands(

auto new_lookup = index_command_lookup(ctx.index);

// Vestigial since the ghost arm began registering its own path (#386): every entry with a
// path is now in path_to_id, so this finds nothing. Kept pending its own removal.
auto ghost_paths = PathIdMap {};
for (auto const& file : ctx.index.files()) {
if (!pup::is_empty(file.path) && !ctx.path_to_id.find(file.path)) {
ghost_paths.insert(file.path, file.id);
}
}

auto find_new_id_by_path = [&](StringId path) -> pup::NodeId {
if (auto found = ctx.path_to_id.find(path)) {
return *found;
}
if (auto found = ghost_paths.find(path)) {
return *found;
}
return pup::INVALID_NODE_ID;
};

Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_string_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2024 Putup authors

#include "catch_amalgamated.hpp"
#include "pup/core/string_id.hpp"
#include "pup/core/string_pool.hpp"

#include <cstdio>
Expand Down Expand Up @@ -112,3 +113,11 @@ TEST_CASE("StringPool Robin Hood index", "[string_pool]")
REQUIRE(moved.find("before_move") == id);
}
}

TEST_CASE("Interning the empty string yields the empty handle", "[string_pool]")
{
auto pool = pup::StringPool {};
REQUIRE(pup::is_empty(pool.intern("")));
REQUIRE_FALSE(pup::is_empty(pool.intern("a")));
REQUIRE(pup::is_empty(pool.intern("")));
}
Loading