Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.690.mcz ==================== Summary ==================== Name: Collections-ul.690 Author: ul Time: 26 April 2016, 2:03:24.991845 am UUID: a58318cb-049e-4741-b337-541b33eb99e7 Ancestors: Collections-cbc.689 - use #basicAt: for string access in the remaining misc primitives - give up on the nil matchTable in ByteString >> #findSubstring:in:startingAt:matchTable: - slightly faster ReadStream >> #upTo: for strings - optimized version of ReadStream >> #skipTo: (this may break #skipTo: for its subclasses, but those shouldn't really exist in the first place) =============== Diff against Collections-cbc.689 =============== Item was changed: ----- Method: ByteString class>>findFirstInString:inSet:startingAt: (in category 'primitives') ----- findFirstInString: aString inSet: inclusionMap startingAt: start | i stringSize | <primitive: 'primitiveFindFirstInString' module: 'MiscPrimitivePlugin'> <var: #aString declareC: 'unsigned char *aString'> <var: #inclusionMap declareC: 'char *inclusionMap'> inclusionMap size ~= 256 ifTrue: [ ^0 ]. i := start. stringSize := aString size. + [ i <= stringSize and: [ (inclusionMap at: (aString basicAt: i) + 1) = 0 ] ] whileTrue: [ - [ i <= stringSize and: [ (inclusionMap at: (aString at: i) asciiValue+1) = 0 ] ] whileTrue: [ i := i + 1 ]. i > stringSize ifTrue: [ ^0 ]. ^i! Item was changed: ----- Method: ByteString class>>indexOfAscii:inString:startingAt: (in category 'primitives') ----- indexOfAscii: anInteger inString: aString startingAt: start | stringSize | <primitive: 'primitiveIndexOfAsciiInString' module: 'MiscPrimitivePlugin'> <var: #aCharacter declareC: 'int anInteger'> <var: #aString declareC: 'unsigned char *aString'> stringSize := aString size. start to: stringSize do: [:pos | + (aString basicAt: pos) = anInteger ifTrue: [^ pos]]. - (aString at: pos) asciiValue = anInteger ifTrue: [^ pos]]. ^ 0 ! Item was changed: ----- Method: ByteString class>>stringHash:initialHash: (in category 'primitives') ----- stringHash: aString initialHash: speciesHash | stringSize hash low | <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'> <var: #aHash declareC: 'int speciesHash'> <var: #aString declareC: 'unsigned char *aString'> stringSize := aString size. hash := speciesHash bitAnd: 16rFFFFFFF. 1 to: stringSize do: [:pos | + hash := hash + (aString basicAt: pos). - hash := hash + (aString at: pos) asciiValue. "Begin hashMultiply" low := hash bitAnd: 16383. hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF. ]. ^ hash! Item was changed: ----- Method: ByteString class>>translate:from:to:table: (in category 'primitives') ----- translate: aString from: start to: stop table: table "translate the characters in the string by the given table, in place" <primitive: 'primitiveTranslateStringWithTable' module: 'MiscPrimitivePlugin'> <var: #table declareC: 'unsigned char *table'> <var: #aString declareC: 'unsigned char *aString'> start to: stop do: [ :i | + aString at: i put: (table at: (aString basicAt: i) + 1) ]! - aString at: i put: (table at: (aString at: i) asciiValue+1) ]! 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]. - matchTable ifNil: [ - start to: body size - key size + 1 do: [ :startIndex | - index := 0. - [ (body at: startIndex + index) == (key at: (index := index + 1)) ] whileTrue: [ - index = key size ifTrue: [ ^startIndex ] ] ]. - ^0 ]. (start max: 1) to: body size - key size + 1 do: [:startIndex | index := 1. + [(matchTable at: (body basicAt: startIndex+index-1) + 1) + = (matchTable at: (key basicAt: 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 "! Item was added: + ----- Method: ReadStream>>skipTo: (in category 'accessing') ----- + skipTo: anObject + "fast version using indexOf:" + + (position := collection indexOf: anObject startingAt: position + 1) = 0 ifTrue: [ + "not present. consume all characters" + position := readLimit. + ^false ]. + ^true! Item was changed: ----- Method: ReadStream>>upTo: (in category 'accessing') ----- upTo: anObject "fast version using indexOf:" | start end | start := position+1. + end := collection indexOf: anObject startingAt: start. - end := collection indexOf: anObject startingAt: start ifAbsent: [ 0 ]. "not present--return rest of the collection" (end = 0 or: [end > readLimit]) ifTrue: [ ^self upToEnd ]. "skip to the end and return the data passed over" position := end. ^collection copyFrom: start to: (end-1)! |
Free forum by Nabble | Edit this page |