The Trunk: Kernel-ul.1008.mcz

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

The Trunk: Kernel-ul.1008.mcz

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

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

Name: Kernel-ul.1008
Author: ul
Time: 30 March 2016, 2:54:12.155092 am
UUID: dee08222-ad83-4daf-a90d-a7a4e7b5009f
Ancestors: Kernel-ul.1007

- minor performance improvements for NumberParser and Fraction.
- give some advantage to the same class integer-integer comparison, which is probably the most common case, in Integer >> #=, at the cost of adding a minor overhead to the integer-non-integer comparisons.
- removed Integer >> #hash because it's not used and the implementation become incorrect over time.

=============== Diff against Kernel-ul.1007 ===============

Item was changed:
  ----- Method: Fraction>>setNumerator:denominator: (in category 'private') -----
  setNumerator: n denominator: d
 
+ d isZero ifTrue: [ ^(ZeroDivide dividend: n) signal ].
+ numerator := n asInteger.
+ (denominator := d asInteger) negative ifTrue: [ "keep sign in numerator"
+ numerator := numerator negated.
+ denominator := denominator negated ]!
- d = 0
- ifTrue: [^(ZeroDivide dividend: n) signal]
- ifFalse:
- [numerator := n asInteger.
- denominator := d asInteger abs. "keep sign in numerator"
- d < 0 ifTrue: [numerator := numerator negated]]!

Item was changed:
  ----- Method: Integer>>= (in category 'comparing') -----
  = aNumber
 
+ aNumber class == self class ifTrue: [ ^(self digitCompare: aNumber) = 0 ].
+ aNumber isInteger ifTrue: [ ^false ].
- aNumber isInteger ifTrue: [
- aNumber class == self class ifFalse: [ ^false ].
- ^(self digitCompare: aNumber) = 0 ].
  aNumber isNumber ifFalse: [ ^false ].
  ^aNumber adaptToInteger: self andCompare: #=!

Item was removed:
- ----- Method: Integer>>hash (in category 'comparing') -----
- hash
- "Hash is reimplemented because = is implemented."
-
- ^(self lastDigit bitShift: 8) + (self digitAt: 1)!

Item was added:
+ ----- Method: NumberParser>>isExponentLetter: (in category 'testing') -----
+ isExponentLetter: aCharacter
+
+ ^self exponentLetters includes: aCharacter!

Item was changed:
  ----- Method: NumberParser>>makeFloatFromMantissa:exponent:base: (in category 'parsing-private') -----
  makeFloatFromMantissa: m exponent: k base: aRadix
  "Convert infinite precision arithmetic into Floating point.
  This alogrithm rely on correct IEEE rounding mode
  being implemented in Integer>>asFloat and Fraction>>asFloat"
 
+ k = 0 ifTrue: [ ^m asFloat ].
+ k > 0 ifTrue: [ ^(m * (aRadix raisedToInteger: k)) asFloat ].
+ ^(Fraction numerator: m denominator: (aRadix raisedToInteger: k negated)) asFloat!
- ^(k positive
- ifTrue: [m * (aRadix raisedToInteger: k)]
- ifFalse: [Fraction numerator: m denominator: (aRadix raisedToInteger: k negated)]) asFloat!

Item was changed:
  ----- Method: NumberParser>>nextElementaryLargeIntegerBase: (in category 'parsing-large int') -----
  nextElementaryLargeIntegerBase: aRadix
  "Form an unsigned integer with incoming digits from sourceStream.
  Return this integer, or zero if no digits found.
  Stop reading if end of digits or if a LargeInteger is formed.
  Count the number of digits and the position of lastNonZero digit and store them in instVar."
 
  | value digit char |
  value := 0.
  nDigits := 0.
  lastNonZero := 0.
+ [
+ value isLarge ifTrue: [ ^value ].
+ char := sourceStream next ifNil: [ ^value ].
+ ((digit := char digitValue) < 0 or: [digit >= aRadix]) ifTrue: [
+ sourceStream skip: -1.
+ ^value ].
+ nDigits := nDigits + 1.
+ digit = 0
+ ifFalse: [
+ lastNonZero := nDigits.
+ value := value * aRadix + digit ]
+ ifTrue: [ value := value * aRadix ] ] repeat!
- [value isLarge or: [(char := sourceStream next) == nil
- or: [digit := char digitValue.
- (0 > digit or: [digit >= aRadix])
- and: [sourceStream skip: -1.
- true]]]]
- whileFalse: [
- nDigits := nDigits + 1.
- 0 = digit
- ifFalse: [lastNonZero := nDigits].
- value := value * aRadix + digit].
- ^value!

Item was changed:
  ----- Method: NumberParser>>readExponent (in category 'parsing-private') -----
  readExponent
  "read the exponent if any (stored in instVar).
  Answer true if found, answer false if none.
  If exponent letter is not followed by a digit,
  this is not considered as an error.
  Exponent are always read in base 10."
 
  | eneg epos |
  exponent := 0.
+ (self isExponentLetter: sourceStream peek) ifFalse: [^ false].
- sourceStream atEnd ifTrue: [^ false].
- (self exponentLetters includes: sourceStream peek)
- ifFalse: [^ false].
  sourceStream next.
  eneg := sourceStream peekFor: $-.
  epos := eneg not and: [self allowPlusSignInExponent and: [sourceStream peekFor: $+]].
  exponent := self nextUnsignedIntegerOrNilBase: 10.
  exponent ifNil: ["Oops, there was no digit after the exponent letter.Ungobble the letter"
  exponent := 0.
  sourceStream
  skip: ((eneg or: [epos])
  ifTrue: [-2]
  ifFalse: [-1]).
  ^ false].
  eneg ifTrue: [exponent := exponent negated].
  ^true!