The Inbox: Collections-cwp.493.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-cwp.493.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-cwp.493.mcz

==================== Summary ====================

Name: Collections-cwp.493
Author: cwp
Time: 24 October 2012, 2:51:20.618 pm
UUID: 0c1728e3-2bdf-4f5b-98d8-1a49539bc32c
Ancestors: Collections-cwp.492

Removed leading- and trailing-keywords support from String>>numArgs. Also extracted the class-specific differences into #canBeToken, so that only String need implement #numArgs.

=============== Diff against Collections-cwp.492 ===============

Item was added:
+ ----- Method: ByteString>>canBeToken (in category 'testing') -----
+ canBeToken
+ "Optimized version for the common case."
+
+ ^ (self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) = 0
+ !

Item was added:
+ ----- Method: String>>canBeToken (in category 'testing') -----
+ canBeToken
+ "Extracted from #numArgs to allow specialization by subclasses"
+
+ ^ self allSatisfy: [:c | c tokenish]!

Item was changed:
  ----- Method: String>>numArgs (in category 'accessing') -----
  numArgs
  "Answer either the number of arguments that the receiver would take if considered a selector.  Answer -1 if it couldn't be a selector.  Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors.  It is intended mostly for the assistance of spelling correction."
 
+ | firstChar numColons start ix |
- | firstChar numColons excess start ix |
  self size = 0 ifTrue: [^ -1].
  firstChar := self at: 1.
+ firstChar isLetter ifTrue:
+ [self canBeToken ifFalse: [^ -1].
- (firstChar isLetter or: [firstChar = $:]) ifTrue:
- ["Fast reject if any chars are non-alphanumeric
- NOTE: fast only for Byte things - Broken for Wide"
- self class isBytes
- ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]]
- ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]].
  "Fast colon count"
  numColons := 0.  start := 1.
+ [(ix := self indexOf: $: startingAt: start) > 0] whileTrue:
+ [numColons := numColons + 1.
+ start := ix + 1].
+ ^ (numColons > 0 and: [self last ~= $:])
+ ifTrue: [^ -1]
+ ifFalse: [numColons]].
- [(ix := self indexOf: $: startingAt: start) > 0]
- whileTrue:
- [numColons := numColons + 1.
- start := ix + 1].
- numColons = 0 ifTrue: [^ 0].
- firstChar = $:
- ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
- ifFalse: [excess := 0].
- self last = $:
- ifTrue: [^ numColons - excess]
- ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
  firstChar isSpecial ifTrue:
  [self size = 1 ifTrue: [^ 1].
  2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
  ^ 1].
  ^ -1.!

Item was added:
+ ----- Method: Symbol>>canBeToken (in category 'testing') -----
+ canBeToken
+ "Since definition of #tokenish depends on a preference, we want to make sure
+ that underscores are always considered tokenish. This is so that selectors created
+ when the preference was turned on don't suddenly become invalid when the
+ preference is turned off."
+
+ ^ self allSatisfy: [:c | c = $_ or: [c tokenish]]!

Item was removed:
- ----- Method: Symbol>>numArgs (in category 'accessing') -----
- numArgs
- "Answer either the number of arguments that the receiver would take if considered a selector.  Answer -1 if it couldn't be a selector.  Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors.  It is intended mostly for the assistance of spelling correction."
-
- | firstChar numColons excess start ix |
- self size = 0 ifTrue: [^ -1].
- firstChar := self at: 1.
- (firstChar isLetter or: [firstChar = $:]) ifTrue:
- [2 to: self size do:
- [:i || c |
- c := self at: i.
- (c = $_ or: [c tokenish]) ifFalse: [^ -1]].
- "Fast colon count"
- numColons := 0.  start := 1.
- [(ix := self indexOf: $: startingAt: start) > 0]
- whileTrue:
- [numColons := numColons + 1.
- start := ix + 1].
- numColons = 0 ifTrue: [^ 0].
- firstChar = $:
- ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
- ifFalse: [excess := 0].
- self last = $:
- ifTrue: [^ numColons - excess]
- ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
- firstChar isSpecial ifTrue:
- [self size = 1 ifTrue: [^ 1].
- 2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
- ^ 1].
- ^ -1.!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-cwp.493.mcz

Levente Uzonyi-2
On Wed, 24 Oct 2012, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-cwp.493.mcz
>
> ==================== Summary ====================
>
> Name: Collections-cwp.493
> Author: cwp
> Time: 24 October 2012, 2:51:20.618 pm
> UUID: 0c1728e3-2bdf-4f5b-98d8-1a49539bc32c
> Ancestors: Collections-cwp.492
>
> Removed leading- and trailing-keywords support from String>>numArgs. Also extracted the class-specific differences into #canBeToken, so that only String need implement #numArgs.

Thanks, this looks great. Instead of writing a mail about my ideas, I
decided to push another version to the Inbox.


Levente

>
> =============== Diff against Collections-cwp.492 ===============
>
> Item was added:
> + ----- Method: ByteString>>canBeToken (in category 'testing') -----
> + canBeToken
> + "Optimized version for the common case."
> +
> + ^ (self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) = 0
> + !
>
> Item was added:
> + ----- Method: String>>canBeToken (in category 'testing') -----
> + canBeToken
> + "Extracted from #numArgs to allow specialization by subclasses"
> +
> + ^ self allSatisfy: [:c | c tokenish]!
>
> Item was changed:
>  ----- Method: String>>numArgs (in category 'accessing') -----
>  numArgs
>   "Answer either the number of arguments that the receiver would take if considered a selector.  Answer -1 if it couldn't be a selector.  Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors.  It is intended mostly for the assistance of spelling correction."
>
> + | firstChar numColons start ix |
> - | firstChar numColons excess start ix |
>   self size = 0 ifTrue: [^ -1].
>   firstChar := self at: 1.
> + firstChar isLetter ifTrue:
> + [self canBeToken ifFalse: [^ -1].
> - (firstChar isLetter or: [firstChar = $:]) ifTrue:
> - ["Fast reject if any chars are non-alphanumeric
> - NOTE: fast only for Byte things - Broken for Wide"
> - self class isBytes
> - ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]]
> - ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]].
>   "Fast colon count"
>   numColons := 0.  start := 1.
> + [(ix := self indexOf: $: startingAt: start) > 0] whileTrue:
> + [numColons := numColons + 1.
> + start := ix + 1].
> + ^ (numColons > 0 and: [self last ~= $:])
> + ifTrue: [^ -1]
> + ifFalse: [numColons]].
> - [(ix := self indexOf: $: startingAt: start) > 0]
> - whileTrue:
> - [numColons := numColons + 1.
> - start := ix + 1].
> - numColons = 0 ifTrue: [^ 0].
> - firstChar = $:
> - ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
> - ifFalse: [excess := 0].
> - self last = $:
> - ifTrue: [^ numColons - excess]
> - ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
>   firstChar isSpecial ifTrue:
>   [self size = 1 ifTrue: [^ 1].
>   2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
>   ^ 1].
>   ^ -1.!
>
> Item was added:
> + ----- Method: Symbol>>canBeToken (in category 'testing') -----
> + canBeToken
> + "Since definition of #tokenish depends on a preference, we want to make sure
> + that underscores are always considered tokenish. This is so that selectors created
> + when the preference was turned on don't suddenly become invalid when the
> + preference is turned off."
> +
> + ^ self allSatisfy: [:c | c = $_ or: [c tokenish]]!
>
> Item was removed:
> - ----- Method: Symbol>>numArgs (in category 'accessing') -----
> - numArgs
> - "Answer either the number of arguments that the receiver would take if considered a selector.  Answer -1 if it couldn't be a selector.  Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors.  It is intended mostly for the assistance of spelling correction."
> -
> - | firstChar numColons excess start ix |
> - self size = 0 ifTrue: [^ -1].
> - firstChar := self at: 1.
> - (firstChar isLetter or: [firstChar = $:]) ifTrue:
> - [2 to: self size do:
> - [:i || c |
> - c := self at: i.
> - (c = $_ or: [c tokenish]) ifFalse: [^ -1]].
> - "Fast colon count"
> - numColons := 0.  start := 1.
> - [(ix := self indexOf: $: startingAt: start) > 0]
> - whileTrue:
> - [numColons := numColons + 1.
> - start := ix + 1].
> - numColons = 0 ifTrue: [^ 0].
> - firstChar = $:
> - ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
> - ifFalse: [excess := 0].
> - self last = $:
> - ifTrue: [^ numColons - excess]
> - ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
> - firstChar isSpecial ifTrue:
> - [self size = 1 ifTrue: [^ 1].
> - 2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
> - ^ 1].
> - ^ -1.!
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-cwp.493.mcz

Colin Putney-3


On Wed, Oct 24, 2012 at 5:07 PM, Levente Uzonyi <[hidden email]> wrote:

Thanks, this looks great. Instead of writing a mail about my ideas, I decided to push another version to the Inbox.

Looks good to me. Pushing to trunk.

ColinĀ