4 ms·
I know nothing about Elixir but I found this curious "You can also see an extra tiny optimization performed by the regex engine — notice that the final string u
by renox 11y ago
I know nothing about Elixir but I found this curious "You can also see an extra tiny optimization performed by the regex engine — notice that the final string uses the ampersand from the original string, rather than from the replacement string".
OK, but why does it need 4 pointers instead of 3 with the beginning slice length incremented (7 bytes)?
- deleted 11y ago[deleted]
- pritambaral 11y agoI guess it already split "Hello &", and the optimization to find out if it can be merged back just hasn't been implemented, or isn't worth implementing.
- jerf 11y agoProbably because that optimization involved a subroutine call to "something expecting to return an iolist", and that subroutine is what noticed it could reuse the ampersand, then tacked on the replacement, then returned the iolist ["&", "amp;"], which the calling routine tacked on to its running list of the result, which was the final return. That's part of what makes iolists nice to work with, in the face of immutable strings in a strict language; you can make subroutine calls that may return a string or an arbitrarily nested list of strings, and you simply write code that unconditionally gathers "Whatever was returned" into a list, instead of sitting there appending all the time. The common "concatenation" operation becomes a list consing instead of a laborious copy.