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

Some slightly performance & style updates #370

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yhx-12243
Copy link

  • In the function fn as_bytes in impl CompactString, there is an redundant slicing (with a self.len() call) which is unnecessary after the update c95edd5.
  • This crate has documented that for 64-bit architectures the capacity will be always inlined. So the logic of is_heap can be replaced with directly returning false to reduce some code generation.

@yhx-12243
Copy link
Author

yhx-12243 commented Mar 10, 2024

It seems that the test needs to be changed, because it's probably that the compiler optimized out the whole test and did not allocate memory at all.

See https://rust.godbolt.org/z/qc349PrGv for a shorter analogue.

@yhx-12243
Copy link
Author

May be we should wrap this test in a something like core::hint::black_box, or maybe do other things to make sure the compiler will not optimize out the "unused" allocation of long string.

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.

None yet

1 participant