fixed redundant calls made by the new message to some collection classes including Set, AssociativeCollection
This commit is contained in:
parent
7689de7dfa
commit
da33ecc167
@ -698,29 +698,39 @@ class Set(Collection)
|
|||||||
{
|
{
|
||||||
var tally, bucket.
|
var tally, bucket.
|
||||||
|
|
||||||
|
method(#class) new
|
||||||
|
{
|
||||||
|
^self new: 16. ### TODO: default size.
|
||||||
|
}
|
||||||
|
|
||||||
method(#class) new: size
|
method(#class) new: size
|
||||||
{
|
{
|
||||||
^self new __initialize_with_size: size.
|
^super new __init_with_capacity: size.
|
||||||
}
|
}
|
||||||
|
|
||||||
method initialize
|
method __init_with_capacity: size
|
||||||
{
|
|
||||||
^self __initialize_with_size: 1. (* TODO: default initial size *)
|
|
||||||
}
|
|
||||||
|
|
||||||
method __initialize_with_size: size
|
|
||||||
{
|
{
|
||||||
if (size <= 0) { size := 2 }.
|
if (size <= 0) { size := 2 }.
|
||||||
self.tally := 0.
|
self.tally := 0.
|
||||||
self.bucket := Array new: size.
|
self.bucket := Array new: size.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method isEmpty
|
||||||
|
{
|
||||||
|
^self.tally == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
method size
|
||||||
|
{
|
||||||
|
^self.tally
|
||||||
|
}
|
||||||
|
|
||||||
method __make_expanded_bucket: bs
|
method __make_expanded_bucket: bs
|
||||||
{
|
{
|
||||||
| newbuc newsz ass index i |
|
| newbuc newsz ass index i |
|
||||||
|
|
||||||
(* expand the bucket *)
|
(* expand the bucket *)
|
||||||
newsz := bs + 32. ## TODO: make this sizing operation configurable.
|
newsz := bs + 16. ## TODO: make this sizing operation configurable.
|
||||||
newbuc := Array new: newsz.
|
newbuc := Array new: newsz.
|
||||||
i := 0.
|
i := 0.
|
||||||
while (i < bs)
|
while (i < bs)
|
||||||
@ -846,16 +856,6 @@ class Set(Collection)
|
|||||||
^(self __find_index: anObject) notError.
|
^(self __find_index: anObject) notError.
|
||||||
}
|
}
|
||||||
|
|
||||||
method isEmpty
|
|
||||||
{
|
|
||||||
^self.tally == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
method size
|
|
||||||
{
|
|
||||||
^self.tally
|
|
||||||
}
|
|
||||||
|
|
||||||
method = aSet
|
method = aSet
|
||||||
{
|
{
|
||||||
ifnot (self class == aSet class) { ^false }.
|
ifnot (self class == aSet class) { ^false }.
|
||||||
@ -882,18 +882,16 @@ class AssociativeCollection(Collection)
|
|||||||
{
|
{
|
||||||
var tally, bucket.
|
var tally, bucket.
|
||||||
|
|
||||||
|
method new
|
||||||
|
{
|
||||||
|
^self new: 16.
|
||||||
|
}
|
||||||
method(#class) new: size
|
method(#class) new: size
|
||||||
{
|
{
|
||||||
^self new __initialize_with_size: size.
|
^super new __init_with_capacity: size.
|
||||||
}
|
}
|
||||||
|
|
||||||
method initialize
|
method __init_with_capacity: size
|
||||||
{
|
|
||||||
^self __initialize_with_size: 128. (* TODO: default initial size *)
|
|
||||||
}
|
|
||||||
|
|
||||||
method __initialize_with_size: size
|
|
||||||
{
|
{
|
||||||
if (size <= 0) { size := 2 }.
|
if (size <= 0) { size := 2 }.
|
||||||
self.tally := 0.
|
self.tally := 0.
|
||||||
|
Loading…
Reference in New Issue
Block a user