[squeak-dev] The Trunk: Collections-tfel.623.mcz

Chris Muller asqueaker at gmail.com
Fri May 1 14:48:49 UTC 2015


I know you are making the Smalltalk code behave teh same as the
primitive but did you consider making the primitive behave the same as
the Smalltalk code and signal an error?

I dunno, if an app is going to calculate a starting position to search
a String and gets it wrong, this code will quietly produce erroneous
results.  Such is the type of bug that could go unnoticed for a long
time.  This seems like one of those things that is low-level enough
that an error should be signaled..

On Fri, May 1, 2015 at 4:06 AM,  <commits at source.squeak.org> wrote:
> Tim Felgentreff uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-tfel.623.mcz
>
> ==================== Summary ====================
>
> Name: Collections-tfel.623
> Author: tfel
> Time: 1 May 2015, 11:06:35.625 am
> UUID: baf2902d-52b9-2442-a513-8a5a6ff0ce30
> Ancestors: Collections-nice.622
>
> fix fallback code for ByteString>>findSubstring:in:startingAt:matchTable: when passing a starting index <= 0
>
> =============== Diff against Collections-nice.622 ===============
>
> Item was changed:
>   ----- Method: ByteString>>findSubstring:in:startingAt:matchTable: (in category 'comparing') -----
>   findSubstring: key in: body startingAt: start matchTable: matchTable
>         "Answer the index in the string body at which the substring key first occurs, at or beyond start.  The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches.  If no match is found, zero will be returned.
>
>         The algorithm below is not optimum -- it is intended to be translated to C which will go so fast that it wont matter."
>         | index |
>         <primitive: 'primitiveFindSubstring' module: 'MiscPrimitivePlugin'>
>         <var: #key declareC: 'unsigned char *key'>
>         <var: #body declareC: 'unsigned char *body'>
>         <var: #matchTable declareC: 'unsigned char *matchTable'>
>
>         key size = 0 ifTrue: [^ 0].
> +       (start max: 1) to: body size - key size + 1 do:
> -       start to: body size - key size + 1 do:
>                 [:startIndex |
>                 index := 1.
>                         [(matchTable at: (body at: startIndex+index-1) asciiValue + 1)
>                                 = (matchTable at: (key at: index) asciiValue + 1)]
>                                 whileTrue:
>                                 [index = key size ifTrue: [^ startIndex].
>                                 index := index+1]].
>         ^ 0
>   "
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 1 matchTable: CaseSensitiveOrder 1
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 2 matchTable: CaseSensitiveOrder 7
>   ' ' findSubstring: 'abc' in: 'abcdefabcd' startingAt: 8 matchTable: CaseSensitiveOrder 0
>   ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseSensitiveOrder 0
>   ' ' findSubstring: 'abc' in: 'abcdefABcd' startingAt: 2 matchTable: CaseInsensitiveOrder 7
>   "!
>
>


More information about the Squeak-dev mailing list