Artifacts Associated With Ticket d2323d6c284a5081
Ticket change [48d7e852f6] (rid 144991) by anonymous on 2016-02-25 14:33:02:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The dubious implementation of tcllib's ::textutil::trim::trimPrefix caught my eye. Why scan the full string when actually looking at the start only? % set haystack [string repeat abc 1000]d % set needle abcd % string first $needle $haystack 2997 % time {string first $needle $haystack} 1000 10.149 microseconds per iteration % time {string first $needle $haystack 0 0} 1000 0.712 microseconds per iteration In this form, I cannot attach my patch file. Will attach or post after creating this ticket. The patch is for the implementation and the tests, not for the documentation. - foundin initialized to: "8.6.4"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "5ef84f1ed636fd4b80333e656cf7dfe1164a9802"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "18. Commands M-Z"
- title initialized to: "add parameter ?lastIndex? to [string first]"
- type initialized to: "Patch"
Add attachment "tcl-8.6.4-string-first.patch" [84d752dff4] (rid 144992) by anonymous on 2016-02-25 14:35:22.
Ticket change [d71370629e] (rid 145228) by dgp on 2016-03-07 18:22:48:
- icomment:
I did not (yet) look at the patch, but if I understand the motivating example of limiting a [string first] search to a subrange of a string, why wouldn't the right answer be to compose [string first] with [string range] ?
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [6cbb73674d] (rid 145233) by anonymous on 2016-03-08 07:47:49:
- 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"
- icomment: