-
Notifications
You must be signed in to change notification settings - Fork 467
Improve allocation of escape_into #655
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
Conversation
In regex-syntax, Make escape_into allocate at most twice (all characters are escaped) instead of more if used on an unallocated String. This way, escape doesn't have to allocate.
Sorry for the second push, added |
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.
LGTM
@hhirtz doesn't it still needs to be allocated later from |
hi @pickfire, I don't really understand the first part of your question, but the patch here made For example, if you called Since Also *Though I don't know any regex meta character that uses more than 1 byte in UTF-8. |
@hhirtz Ah, thanks for the explaination, now I understand it. By the way, if we count first for exactly how many allocations we need, will allocating / reserving once be faster than potentially allocating multiple times? |
Yes, because in most cases reallocation is performed by allocating a larger buffer and copying the previous one into it. If you know how much you want to |
Generally, yes. This is generally referred to as "amortizing allocation" and it greatly influences the structure of a lot of performance critical code. The entire architecture of the regex crate is designed around doing just that. :-) |
In regex-syntax,
Make escape_into allocate at most twice (all characters are escaped)
instead of more if used on an unallocated String. This way, escape
doesn't have to allocate.