From da33ecc16704c30993aec1e4501ec26443dffb20 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 22 Jun 2018 15:27:38 +0000 Subject: [PATCH] fixed redundant calls made by the new message to some collection classes including Set, AssociativeCollection --- moo/kernel/Collect.moo | 50 ++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index 719ca51..1fe1db9 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -698,29 +698,39 @@ class Set(Collection) { var tally, bucket. + method(#class) new + { + ^self new: 16. ### TODO: default size. + } + method(#class) new: size { - ^self new __initialize_with_size: size. + ^super new __init_with_capacity: size. } - method initialize - { - ^self __initialize_with_size: 1. (* TODO: default initial size *) - } - - method __initialize_with_size: size + method __init_with_capacity: size { if (size <= 0) { size := 2 }. self.tally := 0. self.bucket := Array new: size. } + method isEmpty + { + ^self.tally == 0 + } + + method size + { + ^self.tally + } + method __make_expanded_bucket: bs { | newbuc newsz ass index i | (* 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. i := 0. while (i < bs) @@ -846,16 +856,6 @@ class Set(Collection) ^(self __find_index: anObject) notError. } - method isEmpty - { - ^self.tally == 0 - } - - method size - { - ^self.tally - } - method = aSet { ifnot (self class == aSet class) { ^false }. @@ -882,18 +882,16 @@ class AssociativeCollection(Collection) { var tally, bucket. - + method new + { + ^self new: 16. + } method(#class) new: size { - ^self new __initialize_with_size: size. + ^super new __init_with_capacity: size. } - method initialize - { - ^self __initialize_with_size: 128. (* TODO: default initial size *) - } - - method __initialize_with_size: size + method __init_with_capacity: size { if (size <= 0) { size := 2 }. self.tally := 0.