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

[C++] Improve whitespace escaping #3413

Merged
merged 1 commit into from
Dec 23, 2021
Merged

Conversation

jcking
Copy link
Collaborator

@jcking jcking commented Dec 15, 2021

replaceAll is the only function left and its usage is inefficient as its only use case is escaping whitespace. The current usage involves scanning the string 3 times. If any whitespace is actually encountered it updates the string in place, which is terribly slow as std::string is effectively just std::vector with an additional bookkeeping for the null terminator. So updating in place can involve may may memory moves and re-allocations. If there its lots of whitespace to escape, its performance is unacceptable.

Instead an optimal implementation which has a bounded worse case is written inline at its 3 call locations and StringUtils has been removed.

@jcking
Copy link
Collaborator Author

jcking commented Dec 15, 2021

@mike-lischke

@jcking jcking changed the title [C++] Remove support/StringUtils [C++] Improve whitespace escaping Dec 20, 2021
@mike-lischke
Copy link
Member

@parrt A C++ patch ready for merge.

@parrt parrt added this to the 4.9.4 milestone Dec 23, 2021
@parrt parrt merged commit afbd285 into antlr:master Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants