优化大列表增删操作性能

This commit is contained in:
lyswhut
2022-11-09 17:08:12 +08:00
parent 4b22518532
commit 953fc94cb0
7 changed files with 123 additions and 86 deletions
+22
View File
@@ -180,3 +180,25 @@ export const encodePath = (path: string) => {
// https://github.com/lyswhut/lx-music-desktop/issues/963
return path.replaceAll('%', '%25')
}
export const arrPush = <T>(list: T[], newList: T[]) => {
for (let i = 0; i * 1000 < newList.length; i++) {
list.push(...newList.slice(i * 1000, (i + 1) * 1000))
}
return list
}
export const arrUnshift = <T>(list: T[], newList: T[]) => {
for (let i = 0; i * 1000 < newList.length; i++) {
list.splice(i * 1000, 0, ...newList.slice(i * 1000, (i + 1) * 1000))
}
return list
}
export const arrPushByPosition = <T>(list: T[], newList: T[], position: number) => {
for (let i = 0; i * 1000 < newList.length; i++) {
list.splice(position + i * 1000, 0, ...newList.slice(i * 1000, (i + 1) * 1000))
}
return list
}