Optimize spyglass external hash function

This commit is contained in:
Misode
2024-11-26 02:22:34 +01:00
parent 3a467e54b7
commit 46ed105c34
3 changed files with 42 additions and 6 deletions
+10
View File
@@ -7,6 +7,7 @@ import { localize } from '@spyglassmc/locales'
import * as mcdoc from '@spyglassmc/mcdoc'
import * as nbt from '@spyglassmc/nbt'
import * as zip from '@zip.js/zip.js'
import sparkmd5 from 'spark-md5'
import { TextDocument } from 'vscode-languageserver-textdocument'
import type { ConfigGenerator } from '../Config.js'
import siteConfig from '../Config.js'
@@ -59,6 +60,15 @@ export class SpyglassClient {
...BrowserExternals.archive,
decompressBall,
},
crypto: {
// Swap the web crypto sha1 for an md5 implementation, which is about twice as fast
getSha1: async (data: string | Uint8Array) => {
if (typeof data === 'string') {
data = new TextEncoder().encode(data)
}
return sparkmd5.ArrayBuffer.hash(data)
},
},
fs: SpyglassClient.FS,
}