Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return string instead of output pointer in metadata #1671

Merged
merged 5 commits into from
Aug 12, 2023

Conversation

PragmaTwice
Copy link
Member

-void ExtractNamespaceKey(Slice ns_key, std::string *ns, std::string *key, bool slot_id_encoded);
-void ComposeNamespaceKey(const Slice &ns, const Slice &key, std::string *ns_key, bool slot_id_encoded);
-void ComposeSlotKeyPrefix(const Slice &ns, int slotid, std::string *output);
+[[nodiscard]] std::tuple<Slice, Slice> ExtractNamespaceKey(Slice ns_key, bool slot_id_encoded);
+[[nodiscard]] std::string ComposeNamespaceKey(const Slice &ns, const Slice &key, bool slot_id_encoded);
+[[nodiscard]] std::string ComposeSlotKeyPrefix(const Slice &ns, int slotid);
 
 class InternalKey {
  public:
   ...
-  void Encode(std::string *out);
+  [[nodiscard]] std::string Encode() const;

mapleFU
mapleFU previously approved these changes Aug 12, 2023
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

The code LGTM, lets wait for CI and asan, since it might introduce memory problem...

uint8_t namespace_size = 0;
GetFixed8(&ns_key, &namespace_size);
*ns = ns_key.ToString().substr(0, namespace_size);
Slice ns(ns_key.data(), namespace_size);
Copy link
Member

Choose a reason for hiding this comment

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

So this is an optimization that return Slice rather than string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, here it is unnecessary to return string. And if it is required, users can construct string manually from slice.

Copy link
Contributor

@torwig torwig left a comment

Choose a reason for hiding this comment

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

LGTM.

👍

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

LGTM, though it increase the risk of lifetine handling, the patch would improve our style(and make some string copy less)

@PragmaTwice PragmaTwice merged commit b5233c0 into apache:unstable Aug 12, 2023
p1u3o pushed a commit to p1u3o/incubator-kvrocks that referenced this pull request Aug 15, 2023
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.

3 participants