Slang question (was: Re: [squeak-dev] The Trunk: Collections-ul.685.mcz)

Bert Freudenberg bert at freudenbergs.de
Fri Apr 8 10:21:52 UTC 2016


> On 03.04.2016, at 19:45, Levente Uzonyi <leves at caesar.elte.hu> wrote:
> 
> On Sun, 3 Apr 2016, commits at source.squeak.org wrote:
> 
>> Levente Uzonyi uploaded a new version of Collections to project The Trunk:
>> http://source.squeak.org/trunk/Collections-ul.685.mcz
>> 
>> ==================== Summary ====================
>> 
>> Name: Collections-ul.685
>> Author: ul
>> Time: 3 April 2016, 3:21:51.035808 am
>> UUID: db8fd391-2306-4ccc-87d5-b5dee96a78ab
>> Ancestors: Collections-eem.684
>> 
>> Use Spur's new character comparison abilities in some String methods.
>> 
>> =============== Diff against Collections-eem.684 ===============
>> 
>> 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 ].
> 
> I wonder if the #ifNil: check is correct in Slang. 

It’s not correct. Arguably the translation for MiscPrims should deal with it but then there would be special semantics for that, which is probably not a good idea. The way to check arguments in Slang is to see if they have the number of pointer slots you’re expecting.

Besides, for ByteStrings this primitive is always called with a proper matchTable. No check needed.

- Bert -



- Bert -



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4207 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20160408/429718c7/smime.bin


More information about the Squeak-dev mailing list