refactor(scrcpy): small optimizations

This commit is contained in:
Simon Chan 2023-01-20 20:43:43 +08:00
parent 6b23154694
commit b5f58227fd
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
11 changed files with 359 additions and 71 deletions

View file

@ -55,15 +55,32 @@ export function placeholder<T>(): T {
// This library can't use `@types/node` or `lib: dom`
// because they will pollute the global scope
// So `TextEncoder` and `TextDecoder` are not available
// So `TextEncoder` and `TextDecoder` types are not available
// Node.js 8.3 ships `TextEncoder` and `TextDecoder` in `util` module.
// But using top level await to load them requires Node.js 14.1.
// So there is no point to do that. Let's just assume they exist in global.
// @ts-expect-error See reason above
declare class TextEncoderType {
constructor();
encode(input: string): Uint8Array;
}
declare class TextDecoderType {
constructor();
decode(buffer: ArrayBufferView | ArrayBuffer): string;
}
interface GlobalExtension {
TextEncoder: typeof TextEncoderType;
TextDecoder: typeof TextDecoderType;
}
const { TextEncoder, TextDecoder } = globalThis as unknown as GlobalExtension;
const Utf8Encoder = new TextEncoder();
// @ts-expect-error See reason above
const Utf8Decoder = new TextDecoder();
export function encodeUtf8(input: string): Uint8Array {