Skip to content

Commit e955b6d

Browse files
committed
perf(wx-react): 优化geneUUID的性能
1 parent b5962f7 commit e955b6d

File tree

1 file changed

+69
-12
lines changed

1 file changed

+69
-12
lines changed

packages/wx-react/miniprogram_dist/geneUUID.js

+69-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,72 @@
1111
* 高效生成唯一uuid,需要全局不重复
1212
*/
1313

14-
const ORDER = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split('')
15-
let uuid = "a0000000".split('')
14+
const charMap = {
15+
"0": "1",
16+
"1": "2",
17+
"2": "3",
18+
"3": "4",
19+
"4": "5",
20+
"5": "6",
21+
"6": "7",
22+
"7": "8",
23+
"8": "9",
24+
"9": "A",
25+
"A": "B",
26+
"B": "C",
27+
"C": "D",
28+
"D": "E",
29+
"E": "F",
30+
"F": "G",
31+
"G": "H",
32+
"H": "I",
33+
"I": "J",
34+
"J": "K",
35+
"K": "L",
36+
"L": "M",
37+
"M": "N",
38+
"N": "O",
39+
"O": "P",
40+
"P": "Q",
41+
"Q": "R",
42+
"R": "S",
43+
"S": "T",
44+
"T": "U",
45+
"U": "V",
46+
"V": "W",
47+
"W": "X",
48+
"X": "Y",
49+
"Y": "Z",
50+
"Z": "a",
51+
"a": "b",
52+
"b": "c",
53+
"c": "d",
54+
"d": "e",
55+
"e": "f",
56+
"f": "g",
57+
"g": "h",
58+
"h": "i",
59+
"i": "j",
60+
"j": "k",
61+
"k": "l",
62+
"l": "m",
63+
"m": "n",
64+
"n": "o",
65+
"o": "p",
66+
"p": "q",
67+
"q": "r",
68+
"r": "s",
69+
"s": "t",
70+
"t": "u",
71+
"u": "v",
72+
"v": "w",
73+
"w": "x",
74+
"x": "y",
75+
"y": "z",
76+
"z": "0"
77+
}
78+
79+
const uuid = ["a", "0", "0", "0", "0", "0", "0", "0"]
1680
export default function geneUUID() {
1781
let start = 7
1882
while (incr(start) && start > 0) {
@@ -25,13 +89,6 @@ export default function geneUUID() {
2589

2690
function incr(index) {
2791
const v = uuid[index]
28-
29-
if (v === 'z') {
30-
uuid[index] = '0'
31-
return true
32-
} else {
33-
const nextIndex = ORDER.indexOf(v) + 1
34-
uuid[index] = ORDER[nextIndex]
35-
return false
36-
}
37-
}
92+
uuid[index] = charMap[v]
93+
return v === "z"
94+
}

0 commit comments

Comments
 (0)