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

Convert integer to smartstring #37

Closed
douglas-raillard-arm opened this issue Nov 22, 2022 · 3 comments
Closed

Convert integer to smartstring #37

douglas-raillard-arm opened this issue Nov 22, 2022 · 3 comments

Comments

@douglas-raillard-arm
Copy link

Hi,

I was trying to efficiently convert an integer to a smartstring (actually, I want to append it at the end of a smartstring). String has the ToString trait so you can just mystr.push_str(43.to_string()), but there does not seem to be any equivalent for smartstring, unless you convert String to smartstring (but this would allocate then free which would be a perf issue for me).

Any recommendation on how to proceed ?

@schungx
Copy link

schungx commented Nov 22, 2022

It might be difficult to avoid allocation because the text you want to write into the string may push the string over its inline limit.

@douglas-raillard-arm
Copy link
Author

Actually I realized I can use write!() macro to format the number in the smartstring.

It might be difficult to avoid allocation

I meant that I don't want a forced allocation on the typical path (numbers < 64, fixed string prefix of 8 char). Allocating if there is a functional need is ok.

@schungx
Copy link

schungx commented Nov 22, 2022

Actually I realized I can use write!() macro to format the number in the smartstring.

Great deal. I didn't know that!

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

No branches or pull requests

2 participants