summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-05-05 09:17:17 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-05-05 09:17:17 (GMT)
commit5940356ced08a62f3dedc17888f34345dd09af61 (patch)
tree57b6c65d8be2c9b2b531b348b66e93c5a933f7e1
parent92dd14e77c81c060ff6ede641885b928afdb9ec3 (diff)
downloadtcl-5940356ced08a62f3dedc17888f34345dd09af61.zip
tcl-5940356ced08a62f3dedc17888f34345dd09af61.tar.gz
tcl-5940356ced08a62f3dedc17888f34345dd09af61.tar.bz2
Change reallocation growth to 1.5.
-rw-r--r--generic/tclInt.h7
-rw-r--r--tests/listRep.test32
-rw-r--r--tests/stringObj.test12
3 files changed, 26 insertions, 25 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 4d2f85d..660c19f 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2898,9 +2898,10 @@ TclUpsizeAlloc(TCL_UNUSED(Tcl_Size) /*oldSize*/,
Tcl_Size limit)
{
/* assert (oldCapacity < needed <= limit) */
- if (needed < (limit - needed)) {
- return 2 * needed;
- } else {
+ if (needed < (limit - needed/2)) {
+ return needed + needed / 2;
+ }
+ else {
return limit;
}
}
diff --git a/tests/listRep.test b/tests/listRep.test
index 02ff18f..11af9ad 100644
--- a/tests/listRep.test
+++ b/tests/listRep.test
@@ -221,7 +221,7 @@ test listrep-1.2 {
set l [linsert [freeSpaceNone] $end 99]
validate $l
list $l [leadSpace $l] [tailSpace $l]
-} -result [list {0 1 2 3 4 5 6 7 99} 0 9]
+} -result [list {0 1 2 3 4 5 6 7 99} 0 4]
test listrep-1.2.1 {
Inserts at back of unshared list with no free space should allocate all
@@ -231,7 +231,7 @@ test listrep-1.2.1 {
lset l $end+1 99
validate $l
list $l [leadSpace $l] [tailSpace $l]
-} -result [list {0 1 2 3 4 5 6 7 99} 0 9]
+} -result [list {0 1 2 3 4 5 6 7 99} 0 4]
test listrep-1.2.2 {
Inserts at back of unshared list with no free space should allocate all
@@ -241,7 +241,7 @@ test listrep-1.2.2 {
lappend l 99
validate $l
list $l [leadSpace $l] [tailSpace $l]
-} -result [list {0 1 2 3 4 5 6 7 99} 0 9]
+} -result [list {0 1 2 3 4 5 6 7 99} 0 4]
test listrep-1.3 {
Inserts in middle of unshared list with no free space should reallocate with
@@ -1160,7 +1160,7 @@ test listrep-3.3 {
set l [linsert [freeSpaceBoth 8 1 1] $zero -3 -2 -1]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange -3 7] 6 5 1]
+} -result [list [irange -3 7] 3 2 1]
test listrep-3.3.1 {
Inserts in front of unshared spanned list with insufficient total freespace
@@ -1169,7 +1169,7 @@ test listrep-3.3.1 {
set l [lreplace [freeSpaceBoth 8 1 1] $zero -1 -3 -2 -1]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange -3 7] 6 5 1]
+} -result [list [irange -3 7] 3 2 1]
test listrep-3.4 {
Inserts at back of unshared spanned list with room at back should not
@@ -1255,7 +1255,7 @@ test listrep-3.6 {
set l [linsert [freeSpaceBoth 8 1 1] $end 8 9 10]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange 0 10] 1 10 1]
+} -result [list [irange 0 10] 1 4 1]
test listrep-3.6.1 {
Inserts in back of unshared spanned list with insufficient total freespace
@@ -1265,7 +1265,7 @@ test listrep-3.6.1 {
set l [lreplace [freeSpaceBoth 8 1 1] $end+1 $end+1 8 9 10]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange 0 10] 1 10 1]
+} -result [list [irange 0 10] 1 4 1]
test listrep-3.6.2 {
Inserts in back of unshared spanned list with insufficient total freespace
@@ -1276,7 +1276,7 @@ test listrep-3.6.2 {
lappend l 8 9 10
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange 0 10] 1 10 1]
+} -result [list [irange 0 10] 1 4 1]
test listrep-3.6.3 {
Inserts in back of unshared spanned list with insufficient total freespace
@@ -1287,7 +1287,7 @@ test listrep-3.6.3 {
lset l $end+1 8
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list [irange 0 8] 0 9 1]
+} -result [list [irange 0 8] 0 4 1]
test listrep-3.7 {
Inserts in front half of unshared spanned list with room in front should not
@@ -1341,7 +1341,7 @@ test listrep-3.10 {
set l [linsert [freeSpaceBoth 8 1 1] $one -3 -2 -1]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list {0 -3 -2 -1 1 2 3 4 5 6 7} 1 10 1]
+} -result [list {0 -3 -2 -1 1 2 3 4 5 6 7} 1 4 1]
test listrep-3.10.1 {
Inserts in front half of unshared spanned list with insufficient total space.
@@ -1350,7 +1350,7 @@ test listrep-3.10.1 {
set l [lreplace [freeSpaceBoth 8 1 1] $one -1 -3 -2 -1]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list {0 -3 -2 -1 1 2 3 4 5 6 7} 1 10 1]
+} -result [list {0 -3 -2 -1 1 2 3 4 5 6 7} 1 4 1]
test listrep-3.11 {
Inserts in back half of unshared spanned list with room in back should not
@@ -1414,7 +1414,7 @@ test listrep-3.14 {
set l [linsert [freeSpaceBoth 8 1 1] $end-$one 8 9 10]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list {0 1 2 3 4 5 6 8 9 10 7} 1 10 1]
+} -result [list {0 1 2 3 4 5 6 8 9 10 7} 1 4 1]
test listrep-3.14.1 {
Inserts in back half of unshared spanned list with insufficient
@@ -1424,7 +1424,7 @@ test listrep-3.14.1 {
set l [lreplace [freeSpaceBoth 8 1 1] $end -1 8 9 10]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list {0 1 2 3 4 5 6 8 9 10 7} 1 10 1]
+} -result [list {0 1 2 3 4 5 6 8 9 10 7} 1 4 1]
test listrep-3.15 {
Deletes from front of small unshared span list results in elements
@@ -1714,7 +1714,7 @@ test listrep-3.27 {
set l [lreplace [freeSpaceBoth 8 1 1] $zero $one 10 11 12 13 14]
validate $l
list $l [leadSpace $l] [tailSpace $l] [repStoreRefCount $l]
-} -result [list {10 11 12 13 14 2 3 4 5 6 7} 6 5 1]
+} -result [list {10 11 12 13 14 2 3 4 5 6 7} 3 2 1]
test listrep-3.28 {
Replacement of elements at back with same number of elements in unshared
@@ -1770,7 +1770,7 @@ test listrep-3.32 {
set l [lreplace [freeSpaceBoth 8 1 1] $end-1 $end 10 11 12 13 14]
validate $l
list $l [leadSpace $l] [tailSpace $l]
-} -result [list {0 1 2 3 4 5 10 11 12 13 14} 1 10]
+} -result [list {0 1 2 3 4 5 10 11 12 13 14} 1 4]
test listrep-3.33 {
Replacement of elements in the middle in an unshared spanned list with
@@ -1864,7 +1864,7 @@ test listrep-3.41 {
set l [lreplace [freeSpaceBoth 8 1 1] $one $one 8 9 10 11 12]
validate $l
list $l [leadSpace $l] [tailSpace $l]
-} -result [list {0 8 9 10 11 12 2 3 4 5 6 7} 1 11]
+} -result [list {0 8 9 10 11 12 2 3 4 5 6 7} 1 5]
#
# 4.* - tests on shared spanned lists
diff --git a/tests/stringObj.test b/tests/stringObj.test
index 7191ed6..71cf63e 100644
--- a/tests/stringObj.test
+++ b/tests/stringObj.test
@@ -78,7 +78,7 @@ test stringObj-4.3 {Tcl_SetObjLength procedure, string gets longer} testobj {
teststringobj append 1 xyzq -1
list [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
-} {10 21 abcdefxyzq}
+} {10 15 abcdefxyzq}
test stringObj-4.4 {Tcl_SetObjLength procedure, "empty string", length 0} testobj {
testobj freeallvars
testobj newobj 1
@@ -111,7 +111,7 @@ test stringObj-5.3 {Tcl_AppendToObj procedure, reallocating space} testobj {
teststringobj append 1 abcdef -1
lappend result [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
-} {15 15 16 33 xy12345678abcdef}
+} {15 15 16 24 xy12345678abcdef}
test stringObj-6.1 {Tcl_AppendStringsToObj procedure, type conversion} testobj {
testobj freeallvars
@@ -142,7 +142,7 @@ test stringObj-6.5 {Tcl_AppendStringsToObj procedure, don't double space if init
testobj newobj 1
teststringobj appendstrings 1 123 abcdefg
list [teststringobj length 1] [teststringobj length2 1] [teststringobj get 1]
-} {10 21 123abcdefg}
+} {10 15 123abcdefg}
test stringObj-6.6 {Tcl_AppendStringsToObj procedure, space reallocation} testobj {
testobj freeallvars
teststringobj set 1 abc
@@ -160,7 +160,7 @@ test stringObj-6.7 {Tcl_AppendStringsToObj procedure, space reallocation} testob
teststringobj appendstrings 1 34567890x
list [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
-} {11 23 ab34567890x}
+} {11 17 ab34567890x}
test stringObj-6.8 {Tcl_AppendStringsToObj procedure, object totally empty} testobj {
testobj freeallvars
testobj newobj 1
@@ -180,7 +180,7 @@ test stringObj-7.1 {SetStringFromAny procedure} testobj {
teststringobj append 1 x -1
list [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
-} {4 9 {a bx}}
+} {4 6 {a bx}}
test stringObj-7.2 {SetStringFromAny procedure, null object} testobj {
testobj freeallvars
testobj newobj 1
@@ -208,7 +208,7 @@ test stringObj-8.1 {DupStringInternalRep procedure} testobj {
[teststringobj maxchars 1] [teststringobj get 1] \
[teststringobj length 2] [teststringobj length2 2] \
[teststringobj maxchars 2] [teststringobj get 2]
-} {5 11 0 abcde 5 5 0 abcde}
+} {5 8 0 abcde 5 5 0 abcde}
test stringObj-8.2 {DupUnicodeInternalRep, mixed width chars} testobj {
set x abc\xEF\xBF\xAEghi
string length $x