Skip to content

Use StringComparisonAdaptor as key to allow lookup with string_view#628

Open
ahmed0mousa wants to merge 4 commits into
eclipse-score:mainfrom
ahmed0mousa:ahmo_use_string_comparison_adaptor
Open

Use StringComparisonAdaptor as key to allow lookup with string_view#628
ahmed0mousa wants to merge 4 commits into
eclipse-score:mainfrom
ahmed0mousa:ahmo_use_string_comparison_adaptor

Conversation

@ahmed0mousa

Copy link
Copy Markdown
Contributor

No description provided.

…ment maps

Replace std::string keys with score::memory::StringComparisonAdaptor
StringComparisonAdaptor stores the string but allows lookups with std::string_view
without memory allocations, avoiding unnecessary string construction at call sites.

Also updates ContainsEvent/ContainsField/ContainsMethod and
GetServiceElementInstanceDeployment/GetServiceElementId to take std::string_view
instead of const std::string& now that the map key supports it.

Issue: SWP-270173
Update GetQueueSize, GetTypeErasedElementInfo, and GetServiceElementId callers
to take std::string_view instead of const std::string&.

Remove unnecessary std::string{...} constructions from std::string_view parameters
at all call sites in the plumbing layer. This avoids heap allocations when looking
up service elements by name.

Issue: SWP-270173
Call GetAsStringView() when extracting map keys (now StringComparisonAdaptor) for
use as std::string_view, e.g. when logging, inserting into std::set<string_view>,
or passing to functions expecting string_view.

Issue: SWP-270173
…nvertToTracingServiceInstanceElement path

Issue: SWP-270173
using EventIdMapping = std::unordered_map<std::string, EventIdType>;
using FieldIdMapping = std::unordered_map<std::string, FieldIdType>;
using MethodIdMapping = std::unordered_map<std::string, MethodIdType>;
using EventIdMapping = std::unordered_map<score::memory::StringComparisonAdaptor, EventIdType>;

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.

Using StringComparisonAdapter here make very hard to reason about lifetimes. It could be that you own the string and it could be that you do not know the string. If this is only for lookup, is it not possible with custom comparison?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants