j-templates 7.0.43 → 7.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Utils/distinctArray.d.ts +3 -3
- package/Utils/distinctArray.js +7 -9
- package/Utils/thread.js +9 -5
- package/package.json +1 -1
package/Utils/distinctArray.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type DistinctArray<T> = {
|
|
2
|
-
id: (value: T) =>
|
|
3
|
-
distinct:
|
|
2
|
+
id: (value: T) => unknown;
|
|
3
|
+
distinct: Set<unknown> | null;
|
|
4
4
|
array: T[];
|
|
5
5
|
};
|
|
6
6
|
export declare namespace DistinctArray {
|
|
7
|
-
function Create<T>(id: (value: T) =>
|
|
7
|
+
function Create<T>(id: (value: T) => unknown): DistinctArray<T>;
|
|
8
8
|
function Push<T>(distinctArr: DistinctArray<T>, value: T): void;
|
|
9
9
|
function Get<T>({ array }: DistinctArray<T>): T[];
|
|
10
10
|
}
|
package/Utils/distinctArray.js
CHANGED
|
@@ -12,22 +12,20 @@ var DistinctArray;
|
|
|
12
12
|
}
|
|
13
13
|
DistinctArray.Create = Create;
|
|
14
14
|
function Push(distinctArr, value) {
|
|
15
|
-
|
|
16
|
-
switch (array.length) {
|
|
15
|
+
switch (distinctArr.array.length) {
|
|
17
16
|
case 0:
|
|
18
|
-
array.push(value);
|
|
17
|
+
distinctArr.array.push(value);
|
|
19
18
|
break;
|
|
20
19
|
case 1: {
|
|
21
20
|
if (distinctArr.distinct === null) {
|
|
22
|
-
distinctArr.distinct = [];
|
|
23
|
-
distinctArr.distinct[id(array[0])] = true;
|
|
21
|
+
distinctArr.distinct = new Set([distinctArr.id(distinctArr.array[0])]);
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
default: {
|
|
27
|
-
const vId = id(value);
|
|
28
|
-
if (distinctArr.distinct
|
|
29
|
-
distinctArr.distinct
|
|
30
|
-
array.push(value);
|
|
25
|
+
const vId = distinctArr.id(value);
|
|
26
|
+
if (!distinctArr.distinct.has(vId)) {
|
|
27
|
+
distinctArr.distinct.add(vId);
|
|
28
|
+
distinctArr.array.push(value);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
}
|
package/Utils/thread.js
CHANGED
|
@@ -19,7 +19,7 @@ function timeRemaining() {
|
|
|
19
19
|
function createDeadline() {
|
|
20
20
|
return {
|
|
21
21
|
end: Date.now() + workTimeMs,
|
|
22
|
-
timeRemaining
|
|
22
|
+
timeRemaining,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
function ProcessQueue(deadline = createDeadline()) {
|
|
@@ -49,7 +49,9 @@ function DoWork(ctx, deadline = createDeadline()) {
|
|
|
49
49
|
threadContext = ctx;
|
|
50
50
|
const async = ctx.async;
|
|
51
51
|
let callback;
|
|
52
|
-
while (async === ctx.async &&
|
|
52
|
+
while (async === ctx.async &&
|
|
53
|
+
deadline.timeRemaining() > 0 &&
|
|
54
|
+
(callback = list_1.List.Pop(ctx.workList)))
|
|
53
55
|
Invoke(ctx, callback);
|
|
54
56
|
if (ctx.workList.size > 0)
|
|
55
57
|
ScheduleWork(ctx);
|
|
@@ -59,7 +61,7 @@ function CreateContext() {
|
|
|
59
61
|
return {
|
|
60
62
|
async: false,
|
|
61
63
|
workEndNode: null,
|
|
62
|
-
workList: list_1.List.Create()
|
|
64
|
+
workList: list_1.List.Create(),
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
function ScheduleCallback(callback, before, async) {
|
|
@@ -89,7 +91,9 @@ function After(callback) {
|
|
|
89
91
|
}
|
|
90
92
|
function Callback(callback) {
|
|
91
93
|
return function (a, b, c, d) {
|
|
92
|
-
Schedule(function () {
|
|
94
|
+
Schedule(function () {
|
|
95
|
+
callback(a, b, c, d);
|
|
96
|
+
});
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
99
|
var inSynchCallback = false;
|
|
@@ -109,7 +113,7 @@ function Thread(callback) {
|
|
|
109
113
|
Synch(callback);
|
|
110
114
|
}
|
|
111
115
|
function ThreadAsync(callback) {
|
|
112
|
-
return new Promise(resolve => Thread(function (async) {
|
|
116
|
+
return new Promise((resolve) => Thread(function (async) {
|
|
113
117
|
callback(async);
|
|
114
118
|
Thread(resolve);
|
|
115
119
|
}));
|