-
Notifications
You must be signed in to change notification settings - Fork 234
Fix escaping for closing angle brackets. #263
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
|
Hi. Can you sign contributors.txt too? |
| String rest = s.substring(i); | ||
| if (rest.startsWith("\\>")) { | ||
| if (rest.length() == 2 || !rest.substring(2).startsWith(">")) { |
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 looks like it could have poor performance if s is very long. It's better to do these checks without any substring operations, because they involve copying. You should try using charAt(i+1) and charAt(i+2) instead.
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.
I was wondering the same, because I wrote this in the same style as the previous escapes in the method.
Googling around, it seems that in Java 6 (which is the oldest supported by ST4), String#substring was O(1), but with J7+ it is O(n). I'll make the adjustments for this one. For the rest, it seems you've already addressed it in https://github.com/antlr/stringtemplate4/pull/236/files#diff-4b7cd0c18190068c3a0a57ee6c30a9d4L140-L158 )
done I've realized that the previous
I've also changed the substring to startsWith for all cases. Out of curiosity I did some basic benchmarks on some files I had:
|
Clashsoft
left a comment
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.
Looks great!
|
Ok, looks great. Thanks guys. |
This reintroduces closing angle bracket escaping as discussed in #198 .
Note that this applies only to
STGroup, notST-- same way it was in 4.0.4 and prior.