@@ -826,7 +826,7 @@ module array {
826
826
assert(i >= 0);
827
827
assert(i == stack_size - 2 || i == stack_size - 3);
828
828
829
- const elements: HeapObject = ReloadElements(sortState);
829
+ let elements: HeapObject = ReloadElements(sortState);
830
830
const Load: LoadFn = GetLoadFn(sortState);
831
831
832
832
const pending_runs: FixedArray =
@@ -859,6 +859,7 @@ module array {
859
859
const k: Smi = CallGallopRight(
860
860
context, sortState, Load, key_right, base_a, length_a, 0, False)
861
861
otherwise Bailout;
862
+ elements = ReloadElements(sortState);
862
863
assert(k >= 0);
863
864
864
865
base_a = base_a + k;
@@ -874,6 +875,7 @@ module array {
874
875
length_b = CallGallopLeft(
875
876
context, sortState, Load, key_left, base_b, length_b, length_b - 1,
876
877
False) otherwise Bailout;
878
+ elements = ReloadElements(sortState);
877
879
assert(length_b >= 0);
878
880
if (length_b == 0) return kSuccess;
879
881
@@ -893,6 +895,12 @@ module array {
893
895
}
894
896
}
895
897
898
+ macro LoadElementsOrTempArray(
899
+ useTempArray: Boolean, sortState: FixedArray): HeapObject {
900
+ return useTempArray == True ? GetTempArray(sortState) :
901
+ ReloadElements(sortState);
902
+ }
903
+
896
904
// Locates the proper position of key in a sorted array; if the array contains
897
905
// an element equal to key, return the position immediately to the left of
898
906
// the leftmost equal element. (GallopRight does the same except returns the
@@ -916,25 +924,17 @@ module array {
916
924
assert(length > 0 && base >= 0);
917
925
assert(0 <= hint && hint < length);
918
926
919
- // We cannot leave a pointer to elements on the stack (see comment at
920
- // ReloadElements). For this reason we pass a flag whether to reload
921
- // and which array to use.
922
- let elements: HeapObject = useTempArray == True ? GetTempArray(sortState) :
923
- ReloadElements(sortState);
924
-
925
927
let last_ofs: Smi = 0;
926
928
let offset: Smi = 1;
927
929
928
930
try {
929
- const base_hint_element: Object =
930
- CallLoad(context, sortState, Load, elements, base + hint)
931
+ const base_hint_element: Object = CallLoad(
932
+ context, sortState, Load,
933
+ LoadElementsOrTempArray(useTempArray, sortState), base + hint)
931
934
otherwise Bailout;
932
935
let order: Number =
933
936
CallCompareFn(context, sortState, base_hint_element, key)
934
937
otherwise Bailout;
935
- if (useTempArray == False) {
936
- elements = ReloadElements(sortState);
937
- }
938
938
939
939
if (order < 0) {
940
940
// a[base + hint] < key: gallop right, until
@@ -943,14 +943,13 @@ module array {
943
943
// a[base + length - 1] is highest.
944
944
let max_ofs: Smi = length - hint;
945
945
while (offset < max_ofs) {
946
- const offset_element: Object =
947
- CallLoad(context, sortState, Load, elements, base + hint + offset)
946
+ const offset_element: Object = CallLoad(
947
+ context, sortState, Load,
948
+ LoadElementsOrTempArray(useTempArray, sortState),
949
+ base + hint + offset)
948
950
otherwise Bailout;
949
951
order = CallCompareFn(context, sortState, offset_element, key)
950
952
otherwise Bailout;
951
- if (useTempArray == False) {
952
- elements = ReloadElements(sortState);
953
- }
954
953
955
954
// a[base + hint + offset] >= key? Break.
956
955
if (order >= 0) break;
@@ -975,14 +974,13 @@ module array {
975
974
// a[base + hint] is lowest.
976
975
let max_ofs: Smi = hint + 1;
977
976
while (offset < max_ofs) {
978
- const offset_element: Object =
979
- CallLoad(context, sortState, Load, elements, base + hint - offset)
977
+ const offset_element: Object = CallLoad(
978
+ context, sortState, Load,
979
+ LoadElementsOrTempArray(useTempArray, sortState),
980
+ base + hint - offset)
980
981
otherwise Bailout;
981
982
order = CallCompareFn(context, sortState, offset_element, key)
982
983
otherwise Bailout;
983
- if (useTempArray == False) {
984
- elements = ReloadElements(sortState);
985
- }
986
984
987
985
if (order < 0) break;
988
986
@@ -1011,14 +1009,12 @@ module array {
1011
1009
while (last_ofs < offset) {
1012
1010
const m: Smi = last_ofs + ((offset - last_ofs) >>> 1);
1013
1011
1014
- const base_m_element: Object =
1015
- CallLoad(context, sortState, Load, elements, base + m)
1012
+ const base_m_element: Object = CallLoad(
1013
+ context, sortState, Load,
1014
+ LoadElementsOrTempArray(useTempArray, sortState), base + m)
1016
1015
otherwise Bailout;
1017
1016
order = CallCompareFn(context, sortState, base_m_element, key)
1018
1017
otherwise Bailout;
1019
- if (useTempArray == False) {
1020
- elements = ReloadElements(sortState);
1021
- }
1022
1018
1023
1019
if (order < 0) {
1024
1020
last_ofs = m + 1; // a[base + m] < key.
@@ -1051,25 +1047,17 @@ module array {
1051
1047
assert(length > 0 && base >= 0);
1052
1048
assert(0 <= hint && hint < length);
1053
1049
1054
- // We cannot leave a pointer to elements on the stack (see comment at
1055
- // ReloadElements). For this reason we pass a flag whether to reload
1056
- // and which array to use.
1057
- let elements: HeapObject = useTempArray == True ? GetTempArray(sortState) :
1058
- ReloadElements(sortState);
1059
-
1060
1050
let last_ofs: Smi = 0;
1061
1051
let offset: Smi = 1;
1062
1052
1063
1053
try {
1064
- const base_hint_element: Object =
1065
- CallLoad(context, sortState, Load, elements, base + hint)
1054
+ const base_hint_element: Object = CallLoad(
1055
+ context, sortState, Load,
1056
+ LoadElementsOrTempArray(useTempArray, sortState), base + hint)
1066
1057
otherwise Bailout;
1067
1058
let order: Number =
1068
1059
CallCompareFn(context, sortState, key, base_hint_element)
1069
1060
otherwise Bailout;
1070
- if (useTempArray == False) {
1071
- elements = ReloadElements(sortState);
1072
- }
1073
1061
1074
1062
if (order < 0) {
1075
1063
// key < a[base + hint]: gallop left, until
@@ -1078,14 +1066,13 @@ module array {
1078
1066
// a[base + hint] is lowest.
1079
1067
let max_ofs: Smi = hint + 1;
1080
1068
while (offset < max_ofs) {
1081
- const offset_element: Object =
1082
- CallLoad(context, sortState, Load, elements, base + hint - offset)
1069
+ const offset_element: Object = CallLoad(
1070
+ context, sortState, Load,
1071
+ LoadElementsOrTempArray(useTempArray, sortState),
1072
+ base + hint - offset)
1083
1073
otherwise Bailout;
1084
1074
order = CallCompareFn(context, sortState, key, offset_element)
1085
1075
otherwise Bailout;
1086
- if (useTempArray == False) {
1087
- elements = ReloadElements(sortState);
1088
- }
1089
1076
1090
1077
if (order >= 0) break;
1091
1078
@@ -1109,14 +1096,13 @@ module array {
1109
1096
// a[base + length - 1] is highest.
1110
1097
let max_ofs: Smi = length - hint;
1111
1098
while (offset < max_ofs) {
1112
- const offset_element: Object =
1113
- CallLoad(context, sortState, Load, elements, base + hint + offset)
1099
+ const offset_element: Object = CallLoad(
1100
+ context, sortState, Load,
1101
+ LoadElementsOrTempArray(useTempArray, sortState),
1102
+ base + hint + offset)
1114
1103
otherwise Bailout;
1115
1104
order = CallCompareFn(context, sortState, key, offset_element)
1116
1105
otherwise Bailout;
1117
- if (useTempArray == False) {
1118
- elements = ReloadElements(sortState);
1119
- }
1120
1106
1121
1107
// a[base + hint + ofs] <= key.
1122
1108
if (order < 0) break;
@@ -1144,14 +1130,12 @@ module array {
1144
1130
while (last_ofs < offset) {
1145
1131
const m: Smi = last_ofs + ((offset - last_ofs) >>> 1);
1146
1132
1147
- const base_m_element: Object =
1148
- CallLoad(context, sortState, Load, elements, base + m)
1133
+ const base_m_element: Object = CallLoad(
1134
+ context, sortState, Load,
1135
+ LoadElementsOrTempArray(useTempArray, sortState), base + m)
1149
1136
otherwise Bailout;
1150
1137
order = CallCompareFn(context, sortState, key, base_m_element)
1151
1138
otherwise Bailout;
1152
- if (useTempArray == False) {
1153
- elements = ReloadElements(sortState);
1154
- }
1155
1139
1156
1140
if (order < 0) {
1157
1141
offset = m; // key < a[base + m].
@@ -1288,6 +1272,7 @@ module array {
1288
1272
nof_wins_a = CallGallopRight(
1289
1273
context, sortState, Load<TempArrayElements>, key_right,
1290
1274
cursor_temp, length_a, 0, True) otherwise Bailout;
1275
+ elements = ReloadElements(sortState);
1291
1276
assert(nof_wins_a >= 0);
1292
1277
1293
1278
if (nof_wins_a > 0) {
@@ -1313,6 +1298,7 @@ module array {
1313
1298
context, sortState, LoadF, temp_array[cursor_temp], cursor_b,
1314
1299
length_b, 0, False)
1315
1300
otherwise Bailout;
1301
+ elements = ReloadElements(sortState);
1316
1302
assert(nof_wins_b >= 0);
1317
1303
if (nof_wins_b > 0) {
1318
1304
CallCopyWithinSortArray(
@@ -1461,6 +1447,7 @@ module array {
1461
1447
context, sortState, LoadF, temp_array[cursor_temp], baseA,
1462
1448
length_a, length_a - 1, False)
1463
1449
otherwise Bailout;
1450
+ elements = ReloadElements(sortState);
1464
1451
assert(k >= 0);
1465
1452
nof_wins_a = length_a - k;
1466
1453
@@ -1487,6 +1474,7 @@ module array {
1487
1474
k = CallGallopLeft(
1488
1475
context, sortState, Load<TempArrayElements>, key, 0, length_b,
1489
1476
length_b - 1, True) otherwise Bailout;
1477
+ elements = ReloadElements(sortState);
1490
1478
assert(k >= 0);
1491
1479
nof_wins_b = length_b - k;
1492
1480
@@ -1743,8 +1731,7 @@ module array {
1743
1731
// 2. Let obj be ? ToObject(this value).
1744
1732
const obj: JSReceiver = ToObject(context, receiver);
1745
1733
1746
- const sort_state: FixedArray =
1747
- AllocateZeroedFixedArray(kSortStateSize);
1734
+ const sort_state: FixedArray = AllocateZeroedFixedArray(kSortStateSize);
1748
1735
FillFixedArrayWithSmiZero(sort_state, SmiTag(kSortStateSize));
1749
1736
1750
1737
sort_state[kReceiverIdx] = obj;
0 commit comments