The Trunk: Regex-Core-ul.46.mcz

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

The Trunk: Regex-Core-ul.46.mcz

commits-2
Levente Uzonyi uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ul.46.mcz

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

Name: Regex-Core-ul.46
Author: ul
Time: 26 March 2016, 7:18:24.505619 pm
UUID: d7cbc4e5-32ee-4ea3-9228-ff39b3c76af7
Ancestors: Regex-Core-ul.45

Few more RxMatchOptimizer tweaks:
- prefixes, nonPrefixes, predicates, nonPredicates can never be empty
- #predicateTester creates better blocks
- removed the never sent #addNonPrefix: method

RxMatcher >> #atEndOfLine considers line feed as end of line as well.

=============== Diff against Regex-Core-ul.45 ===============

Item was removed:
- ----- Method: RxMatchOptimizer>>addNonPrefix: (in category 'private') -----
- addNonPrefix: aCharacter
-
- ^(nonPrefixes ifNil: [ nonPrefixes := CharacterSet new ]) add: aCharacter!

Item was changed:
  ----- Method: RxMatchOptimizer>>addNonPrefixes: (in category 'private') -----
  addNonPrefixes: aSet
 
+ aSet size = 0 ifTrue: [ ^aSet ].
  ^nonPrefixes
  ifNil: [ nonPrefixes := aSet ]
  ifNotNil: [ nonPrefixes addAll: aSet ]!

Item was changed:
  ----- Method: RxMatchOptimizer>>addPrefixes: (in category 'private') -----
  addPrefixes: aSet
 
+ aSet size = 0 ifTrue: [ ^aSet ].
  ^prefixes
  ifNil: [ prefixes := aSet ]
  ifNotNil: [ prefixes addAll: aSet ]!

Item was changed:
  ----- Method: RxMatchOptimizer>>nonPredicateTester (in category 'private') -----
  nonPredicateTester
 
+ | p |
- | p size |
  nonPredicates ifNil: [ ^nil ].
+ nonPredicates size = 1 ifTrue:  [
- (size := nonPredicates size) = 0 ifTrue: [ ^nil ].
- size = 1 ifTrue:  [
  | predicate |
  predicate := nonPredicates anyOne.
+ ^[ :char :matcher | (predicate value: char) not ] ].
- ^[ :char :matcher | (predicate value: char) not] ].
  p := nonPredicates asArray.
+ ^[ :char :matcher | (p allSatisfy: [ :some | some value: char ]) not ]!
- ^[ :char :m | (p allSatisfy: [:some | some value: char ]) not ]!

Item was changed:
  ----- Method: RxMatchOptimizer>>nonPrefixTester (in category 'private') -----
  nonPrefixTester
 
- | size |
  nonPrefixes ifNil: [ ^nil ].
+ nonPrefixes size = 1 ifTrue: [
- (size := nonPrefixes size) = 0 ifTrue: [ ^nil ].
- size = 1 ifTrue: [
  | nonPrefixChar |
  nonPrefixChar := nonPrefixes anyOne.
  ^[ :char :matcher | char ~~ nonPrefixChar ] ].
  ^[ :char : matcher | (nonPrefixes includes: char) not ]!

Item was changed:
  ----- Method: RxMatchOptimizer>>predicateTester (in category 'private') -----
  predicateTester
 
+ | p |
- | p size |
  predicates ifNil: [ ^nil ].
+ predicates size = 1 ifTrue: [
- (size := predicates size) = 0 ifTrue: [ ^nil ].
- size = 1 ifTrue: [
  | pred |
  pred := predicates anyOne.
  ^[ :char :matcher | pred value: char ] ].
  p := predicates asArray.
  ^[ :char :matcher | p anySatisfy: [:some | some value: char ] ]!

Item was changed:
  ----- Method: RxMatchOptimizer>>prefixTester (in category 'private') -----
  prefixTester
 
+ | p |
- | p size |
  prefixes ifNil: [ ^nil ].
+ prefixes size = 1 ifTrue: [
- (size := prefixes size) = 0 ifTrue: [ ^nil ].
- size = 1 ifTrue: [
  | prefixChar |
  prefixChar := prefixes anyOne.
+ ignoreCase ifTrue: [
+ | lowercasePrefixChar |
+ lowercasePrefixChar := prefixChar asLowercase.
+ prefixChar := prefixChar asUppercase.
+ prefixChar == lowercasePrefixChar ifFalse: [
+ ^[ :char :matcher | char == prefixChar or: [ char == lowercasePrefixChar ] ] ] ].
- ignoreCase ifTrue: [ ^[ :char :matcher | char sameAs: prefixChar ] ].
  ^[ :char :matcher | char == prefixChar ] ].
+ ignoreCase ifTrue: [
+ prefixes copy do: [ :each |
+ | character |
+ (character := each asUppercase) == each ifFalse: [
+ prefixes add: character ].
+ (character := each asUppercase) == each ifFalse: [
+ prefixes add: character ] ] ].
+ prefixes size < 10 ifTrue: [ "10 is an empirical value"
+ p := prefixes asArray.
+ ^[ :char :matcher | p instVarsInclude: char ] ].
+ ^[ :char :matcher | prefixes includes: char ]!
- ignoreCase ifFalse: [ ^[ :char :matcher | prefixes includes: char ] ].
- p := prefixes collect: [ :each | each asUppercase ].
- ^[ :char :matcher | p includes: char asUppercase ]!

Item was changed:
  ----- Method: RxMatcher>>atEndOfLine (in category 'testing') -----
  atEndOfLine
 
+ | peek |
+ (peek := stream peek ifNil: [ ^true ]) == Cr ifTrue: [ ^true ].
+ ^peek == Lf!
- ^self atEnd or: [stream peek = Cr]!