-
Notifications
You must be signed in to change notification settings - Fork 77
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
add length()
and is_empty()
to Buffer
#1044
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Pull Request Test Coverage Report for Build 3588Details
💛 - Coveralls |
builtin/buffer.mbt
Outdated
@@ -72,6 +72,16 @@ fn grow_if_necessary(self : Buffer, required : Int) -> Unit { | |||
} | |||
} | |||
|
|||
/// Return the given buffer's length in bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is encoding agnostics? How is it useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobzhang This API mirrors OCaml's Buffer.length
which counts in bytes (i.e. char
s in OCaml), so it is indeed encoding agnostic. Currently it's feasible via b.to_bytes().length()
(example), but .to_bytes()
introduces an extra copy.
Although in Cmarkit this API is only used to check whether the buffer is empty (namely length b <> 0
), other use cases do exist, notably getting a copy of the underlying Bytes
towards its end via Buffer.sub
(e.g. sub b 42 (length b - 1 - 42)
).
Thus, I think it would still be beneficial to expose the buffer length. Of course, I'd be happy to withdraw the .length()
API if you consider this to be unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are moving buffer outside builtin to provide a dedicated buffer package mimicking ocaml's behavior cc @hackwaly
related #1084 |
@rami3l can you cherry pick these APIs into the new buffer package |
661a8cf
to
e661942
Compare
From the provided
These observations are based on the provided |
May I ask what is blocking this PR from being merged? Many thanks in advance :) |
721403b
to
1326d2e
Compare
As required in the Markdown parser implementation.