Added new method `Smalltalk class>>size` jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 03 Jul 2017 22:01:55 +0200
branchjv
changeset 23077 a68e1e09f73a
parent 23076 3f08e9d58571
child 23078 716f3fbb09e9
Added new method `Smalltalk class>>size` ...that returns a number of all globas. To do so without an allocation of temporary shadow array, make use of new VM entry: `__GLOBALS_SIZE()`. Udated #keys and #values to preallocate collections to avoid reallocation.
Smalltalk.st
--- a/Smalltalk.st	Mon Jul 03 21:50:06 2017 +0200
+++ b/Smalltalk.st	Mon Jul 03 22:01:55 2017 +0200
@@ -1253,7 +1253,7 @@
 
     |keys|
 
-    keys := IdentitySet new.
+    keys := IdentitySet new: self size.
     self keysDo:[:k | keys add:k].
     ^ keys
 !
@@ -1290,7 +1290,7 @@
 
     |values|
 
-    values := OrderedCollection new.
+    values := OrderedCollection new: self size.
     self do:[:v | values add:v].
     ^ values
 
@@ -3691,6 +3691,17 @@
     "Modified: / 14.6.1998 / 15:54:03 / cg"
 !
 
+size
+    "Return the number of globals"
+
+%{
+    return __MKINT( __GLOBALS_SIZE() ) ;
+%}.
+    self primitiveFailed.
+
+    "Created: / 03-07-2017 / 21:47:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 someImplementorOf:aSelector
     "return any class, which implement the given selector. Nil if there is none.
      (useful to search, if there is one at all)"