mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-19 15:54:09 +02:00
NETSCRIPT: Greatly speed up script launching, and remove the limitation unique args per script (#440)
* Remove the limitation unique args per script * Internal changes to how runningScripts are stored on the server, to make common usage faster.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { ScriptArg } from "../../Netscript/ScriptArg";
|
||||
import type { ScriptFilePath } from "../../Paths/ScriptFilePath";
|
||||
|
||||
// This needs to be high in the dependency graph, with few/no dependencies of
|
||||
// its own, since many key modules depend on it.
|
||||
|
||||
export type ScriptKey = string /*& { __type: "ScriptKey" }*/;
|
||||
|
||||
// The key used to lookup worker scripts in their map.
|
||||
export function scriptKey(path: ScriptFilePath, args: ScriptArg[]): ScriptKey {
|
||||
// Asterisk is used as a delimiter because it' not a valid character in paths.
|
||||
return (path + "*" + JSON.stringify(args)) as ScriptKey;
|
||||
}
|
||||
|
||||
// Returns a RegExp that can be used to find scripts with a path that fully
|
||||
// matches "pattern" in the scriptKey.
|
||||
export function matchScriptPathExact(pattern: string) {
|
||||
// Must fully match pattern, starting at the beginning and ending with the
|
||||
// asterisk delimiter, which can't appear in script paths.
|
||||
return new RegExp("^" + pattern + "\\*");
|
||||
}
|
||||
|
||||
// Returns a RegExp that can be used to find scripts with a path that
|
||||
// matches "pattern" somewhere in the scriptKey.
|
||||
export function matchScriptPathUnanchored(pattern: string) {
|
||||
// Don't let the match extend into the arguments part (script paths can't
|
||||
// include "[").
|
||||
return matchScriptPathExact("[^[]*" + pattern + "[^[]*");
|
||||
}
|
||||
Reference in New Issue
Block a user