Overview
| Artifact ID: | 6cbb73674d8e9df16fb3271d791f545ac618d6a5 |
|---|---|
| Ticket: | d2323d6c284a5081e818dc02f0bbe695a7aa1c61
add parameter ?lastIndex? to [string first] |
| User & Date: | anonymous on 2016-03-08 07:47:49 |
Changes
- icomment:
> to compose [string first] with [string range] This was my first assumption when looking at the implementation of trimPrefix. Then I thought that someone might have chosen to _not_ create a copy of the prefix of size of needle. And [string first $needle [string range $haystack 0 [string length $needle]-1]] is somewhat lengthy. % time {string first $needle $haystack} 1000 13.128 microseconds per iteration % time {string first $needle [string range $haystack 0 [string length $needle]-1]} 1000 1.435 microseconds per iteration % # other machine than the above measurement: assuming +50% to +100% slower than [string first $needle $haystack 0 0]; % # also note that a string comparison (not integer as after [string first]) is still left to trimPrefix ... In the end, I looked at the C code and found that it was an easy task to add this feature. It is an extension that might or might not be interesting for the community. I package our custom version from pristine sources and can therefore easily provide the patch as-is. I added tests, but no doc. OT: I also considered another patch to allow multiple + and - in the index, e.g. consider the postfix scenario [string range $haystack end-[string length $needle]+1 end]. - login: "anonymous"
- mimetype: "text/plain"
- username: "heinrichmartin"