Skip to content

Commit 4cff94c

Browse files
committed
feat(perf): use TypedArray.subarray() instead of .slice()
1 parent c9f97d8 commit 4cff94c

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
"kernel32",
4646
"user32",
4747
"shell32",
48-
"demos"
48+
"advapi32",
49+
"demos",
50+
"all"
4951
],
5052
"cSpell.words": [
5153
"advapi",

source/win32/advapi32/token.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export function LookupAccountSid(
7171
return LookupAccountSid.fn(lpSystemName, Sid, name, cchName, referencedDomainName, cchReferencedDomainName, peUse) === 0
7272
? null
7373
: {
74-
Name: textDecoder.decode(name.slice(0, cchName[0])),
75-
ReferencedDomainName: textDecoder.decode(referencedDomainName.slice(0, cchReferencedDomainName[0])),
74+
Name: textDecoder.decode(name.subarray(0, cchName[0])),
75+
ReferencedDomainName: textDecoder.decode(referencedDomainName.subarray(0, cchReferencedDomainName[0])),
7676
peUse: peUse[0]
7777
}
7878
}

source/win32/kernel32/error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function FormatMessage(dwFlags: FORMAT_MESSAGE_ | number, lpSource: HMODU
2020
out, out.length,
2121
'int', 0 // Fake va_list
2222
)
23-
return textDecoder.decode(out.slice(0, len))
23+
return textDecoder.decode(out.subarray(0, len))
2424
}
2525

2626
/** @internal */

source/win32/kernel32/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function GetModuleFileName(hModule: HMODULE): string | null {
1313

1414
const out = new Uint16Array(1024)
1515
const len = GetModuleFileName.fn(hModule, out, out.length)
16-
return textDecoder.decode(out.slice(0, len))
16+
return textDecoder.decode(out.subarray(0, len))
1717
}
1818

1919
/** @internal */

source/win32/kernel32/process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function QueryFullProcessImageName(hProcess: HANDLE, dwFlags: number): st
6262
const dwSize: NUMBER_OUT = [ exeName.length ]
6363
return QueryFullProcessImageName.fn(hProcess, dwFlags, exeName, dwSize) === 0
6464
? null
65-
: textDecoder.decode(exeName.slice(0, dwSize[0]))
65+
: textDecoder.decode(exeName.subarray(0, dwSize[0]))
6666
}
6767

6868
/** @internal */

source/win32/user32/window.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export function GetWindowText(hWnd: HWND): string {
267267

268268
const out = new Uint16Array(512)
269269
const len = GetWindowText.fn(hWnd, out, out.length)
270-
return textDecoder.decode(out.slice(0, len))
270+
return textDecoder.decode(out.subarray(0, len))
271271
}
272272

273273
/** @internal */

source/win32/user32/wndclass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function GetClassName(hWnd: HWND): string {
119119

120120
const out = new Uint16Array(128)
121121
const len = GetClassName.fn(hWnd, out, out.length)
122-
return textDecoder.decode(out.slice(0, len))
122+
return textDecoder.decode(out.subarray(0, len))
123123
}
124124

125125
/** @internal */

0 commit comments

Comments
 (0)