Skip to content
Tcl Source Code History Of Ticket d2323d6c284a5081
Login

History Of Ticket d2323d6c284a5081

Artifacts Associated With Ticket d2323d6c284a5081

  1. Ticket change [48d7e852f6] (rid 144991) by anonymous on 2016-02-25 14:33:02:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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.
      
    5. foundin initialized to: "8.6.4"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "5ef84f1ed636fd4b80333e656cf7dfe1164a9802"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "18. Commands M-Z"
    15. title initialized to: "add parameter ?lastIndex? to [string first]"
    16. type initialized to: "Patch"
  2. Add attachment "tcl-8.6.4-string-first.patch" [84d752dff4] (rid 144992) by anonymous on 2016-02-25 14:35:22.

  3. Ticket change [d71370629e] (rid 145228) by dgp on 2016-03-07 18:22:48:

    1. 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] ?
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  4. Ticket change [6cbb73674d] (rid 145233) by anonymous on 2016-03-08 07:47:49:

    1. 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].
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
    4. username: "heinrichmartin"