antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

Fix escaping for closing angle brackets. #263

Closed peteruhnak closed 4 years ago

peteruhnak commented 4 years ago

This reintroduces closing angle bracket escaping as discussed in https://github.com/antlr/stringtemplate4/issues/198 .

Note that this applies only to STGroup, not ST -- same way it was in 4.0.4 and prior.

parrt commented 4 years ago

Hi. Can you sign contributors.txt too?

peteruhnak commented 4 years ago

Hi. Can you sign contributors.txt too?

done

I've realized that the previous \>> case was a subset of the new one so I merged them.

This looks like it could have poor performance if s is very long.

I've also changed the substring to startsWith for all cases.


Out of curiosity I did some basic benchmarks on some files I had:

test name ops/s size in chars ops/s * size
EscapeChangePerf.benchTinySubstring 2,059,220 34 70,013,489
EscapeChangePerf.benchTinyStartsWith 3,154,894 34 107,266,400
EscapeChangePerf.benchTinyChar 10,831,791 34 368,280,883
       
EscapeChangePerf.benchSmallSubstring 75,085 966 72,532,051
EscapeChangePerf.benchSmallStartsWith 128,906 966 124,522,734
EscapeChangePerf.benchSmallChar 455,153 966 439,677,458
       
EscapeChangePerf.benchMediumSubstring 7,465 5,403 40,330,775
EscapeChangePerf.benchMediumStartsWith 24,014 5,403 129,749,603
EscapeChangePerf.benchMediumChar 96,988 5,403 524,023,722
       
EscapeChangePerf.benchLargeSubstring 628 22,556 14,165,145
EscapeChangePerf.benchLargeStartsWith 5,713 22,556 128,858,481
EscapeChangePerf.benchLargeChar 21,201 22,556 478,209,418
parrt commented 4 years ago

Ok, looks great. Thanks guys.