Skip to content

Commit a1fd2e0

Browse files
committed
Fix: ItemValue Property Editor, Fast Entry works slow for several hunderds items #903
1 parent 929b81b commit a1fd2e0

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/surveyHelper.ts

+11-27
Original file line numberDiff line numberDiff line change
@@ -170,39 +170,23 @@ export class SurveyHelper {
170170
dest.splice(0, dest.length);
171171
return;
172172
}
173-
var destHash = SurveyHelper.applyItemValueArrayCreateHash(dest);
174-
var srcHash = SurveyHelper.applyItemValueArrayCreateHash(src);
175-
for (var i = 0; i < dest.length; i++) {
176-
var ind = srcHash[dest[i].value];
177-
dest[i].srcIndex = ind === undefined ? -1 : ind;
173+
if (dest.length > src.length) {
174+
dest.splice(src.length, dest.length - src.length);
178175
}
179-
var insertIndex = 0;
180-
for (var i = 0; i < src.length; i++) {
181-
var ind = destHash[src[i].value];
182-
if (ind === undefined) {
183-
dest.splice(insertIndex, 0, src[i]);
184-
insertIndex++;
185-
} else {
186-
insertIndex = ind + 1;
176+
if (dest.length < src.length) {
177+
var insertedArray = [];
178+
for (var i = dest.length; i < src.length; i++) {
179+
insertedArray.push(src[i]);
187180
}
181+
dest.splice.apply(dest, [dest.length, 0].concat(insertedArray));
188182
}
189-
for (var i = dest.length - 1; i >= 0; i--) {
190-
if (dest[i].srcIndex === -1) {
191-
dest.splice(i, 1);
192-
} else {
193-
if (dest[i].srcIndex > -1 && src[dest[i].srcIndex].hasText) {
194-
dest[i].text = src[dest[i].srcIndex].text;
195-
}
183+
for (var i = 0; i < dest.length; i++) {
184+
if (dest[i].value != src[i].value) {
185+
dest[i].value = src[i].value;
196186
}
187+
dest[i].text = src[i].hasText ? src[i].text : "";
197188
}
198189
}
199-
private static applyItemValueArrayCreateHash(arr: Array<Survey.ItemValue>) {
200-
var res = {};
201-
for (var i = 0; i < arr.length; i++) {
202-
res[arr[i].value] = i;
203-
}
204-
return res;
205-
}
206190
public static disableSelectingObj(obj: Survey.Base) {
207191
obj["disableSelecting"] = true;
208192
}

tests/propertyEditors/propertyEditorsTests.ts

+9
Original file line numberDiff line numberDiff line change
@@ -2491,4 +2491,13 @@ QUnit.test("SurveyHelper.applyItemValueArray", function (assert) {
24912491
[1, { value: 2, text: "item 2" }, { value: 4, text: "item 4" }],
24922492
7
24932493
);
2494+
testSetFunc([1, 2, 2, 3, 4, 5, 6], [1, 2, 2, 3], 8);
2495+
testSetFunc([1, 2, 3, 4, 2, 5, 6], [1, 2, 3, 2], 9);
2496+
console.log(q2.toJSON());
2497+
testSetFunc(
2498+
[1, 2, 13, 14, 5, 6],
2499+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
2500+
10
2501+
);
2502+
console.log(q2.toJSON());
24942503
});

0 commit comments

Comments
 (0)