Hi Levente,<br>
<br>
> I thought you deliberately wanted to use regular expressions there.<br>
<br>
Not at any price, I guess. :-) In a recent project, I have identified regular expressions as bottlenecks pretty often - the parser only eats up pretty much resources compared to a simple in-line string transformation. What would be your preferred approach here?<br>
<br>
> If you want the "Best Performance (tm)", there is a Squeak-specific pattern for these kinds of string-rewrite methods, which consists of a precomputed character set and the use of #new:streamContents:, #indexOfAnyOf:startingAt: and #next:putAll:startingAt:.<br>
> String's #format:, #expandMacrosWithArguments:, #unescapePercentsRaw and #jsonWriteOn: (only if you have JSON-ul.56 in your image) all use that pattern.<br>
<br>
Thanks for the tip! Should I bound the size of the string to stream from above or from below? #unescapePercentsRaw and #expandMacrosWithArguments: bound from below but #format: bounds from above.<br>
<br>
Best,<br>
Christoph<br>
<br>
> Hi Christoph,<br>
> <br>
> On Thu, 8 Jul 2021, christoph.thiede at student.hpi.uni-potsdam.de wrote:<br>
> <br>
> > Hi Levente,<br>
> > <br>
> > two very fair points, thank you for the feedback! Revisiting #escapeString: again, we do not even need to compile a new regex, which is really expensive, but we can use a simple loop instead:<br>
> <br>
> I thought you deliberately wanted to use regular expressions there.<br>
> <br>
> > <br>
> >     | special |<br>
> >     special := self specialCharacters.<br>
> >     ^ String streamContents: [:stream |<br>
> >         aString do: [:char |<br>
> >             (special includes: char) ifTrue: [stream nextPut: $\].<br>
> >             stream nextPut: char]]<br>
> > <br>
> > Which is 90% faster than the original approach. :-)<br>
> <br>
> If you want the "Best Performance (tm)", there is a Squeak-specific <br>
> pattern for these kinds of string-rewrite methods, which consists of a <br>
> precomputed character set and the use of #new:streamContents:, <br>
> #indexOfAnyOf:startingAt: and #next:putAll:startingAt:.<br>
> String's #format:, #expandMacrosWithArguments:, #unescapePercentsRaw <br>
> and #jsonWriteOn: (only if you have JSON-ul.56 in your image) all use that <br>
> pattern.<br>
> <br>
> <br>
> Levente<br>
> <br>
> <br>
<br>
---<br>
<br>
<i><font color="#00000088">Sent from </font></i><i><u><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><font color="#00000088">Squeak Inbox Talk</font></a></u></i>