The Trunk: Kernel-ul.666.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.666.mcz

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

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

Name: Kernel-ul.666
Author: ul
Time: 23 January 2012, 3:19:39.301 am
UUID: 7a3266d0-57d3-3149-992f-5d3a6959c043
Ancestors: Kernel-nice.665

- Fixed Integer >> #isPowerOfTwo which returned true for 0. Added optimized versions to Integer's subclasses.
- Updated MethodDictionary class >> #sizeFor: to be error resistant if the semantics of #asLargerPowerOfTwo would change.

=============== Diff against Kernel-nice.665 ===============

Item was changed:
  ----- Method: Integer>>isPowerOfTwo (in category 'testing') -----
  isPowerOfTwo
  "Return true if the receiver is an integral power of two."
+
+ ^self strictlyPositive and: [ (self bitAnd: self - 1) = 0 ]!
- ^ (self bitAnd: self-1) = 0!

Item was added:
+ ----- Method: LargeNegativeInteger>>isPowerOfTwo (in category 'testing') -----
+ isPowerOfTwo
+ "Return true if the receiver is an integral power of two. Optimized version."
+
+ ^false!

Item was added:
+ ----- Method: LargePositiveInteger>>isPowerOfTwo (in category 'testing') -----
+ isPowerOfTwo
+ "Return true if the receiver is an integral power of two. Optimized version."
+
+ | size |
+ 1 to: (size := self digitLength) do: [ :index |
+ | digit |
+ (digit := self digitAt: index) = 0 ifFalse: [
+ ^size = index and: [ digit isPowerOfTwo ] ] ].
+ ^false!

Item was changed:
  ----- Method: MethodDictionary class>>sizeFor: (in category 'sizing') -----
  sizeFor: numberOfElements
  "Return the minimum capacity of a dictionary that can hold numberOfElements elements. At least 25% of the array must be empty and the return value must be a power of 2."
 
+ ^(numberOfElements * 4 // 3 max: 1) asLargerPowerOfTwo!
- ^(numberOfElements * 4 // 3) asLargerPowerOfTwo max: 1!

Item was added:
+ ----- Method: SmallInteger>>isPowerOfTwo (in category 'testing') -----
+ isPowerOfTwo
+ "Return true if the receiver is an integral power of two. Optimized version."
+
+ ^self > 0 and: [ (self bitAnd: self - 1) = 0 ]!