- Fixed a buged while condition inside path_resolver.ts
- Fixed `NodePointer` class to work with by reference comparison (maps use that) so the reverse index can look up entries properly`. `NodePointer` now caches every pointer created so logic can use reference comparison
This commit is contained in:
@@ -4,6 +4,8 @@ export type NodeHash = ReadonlyMap<number, Node>;
|
|||||||
export type ShadowHash = ReadonlyMap<number, Node | null>;
|
export type ShadowHash = ReadonlyMap<number, Node | null>;
|
||||||
|
|
||||||
export class NodePointer {
|
export class NodePointer {
|
||||||
|
private static readonly _cache = new Map<string, NodePointer>();
|
||||||
|
|
||||||
private readonly _device_id: number;
|
private readonly _device_id: number;
|
||||||
private readonly _inode: number;
|
private readonly _inode: number;
|
||||||
|
|
||||||
@@ -13,13 +15,24 @@ export class NodePointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static of(device_id: number, inode: number): NodePointer {
|
static of(device_id: number, inode: number): NodePointer {
|
||||||
return new NodePointer(device_id, inode);
|
const key = `${device_id}:${inode}`;
|
||||||
|
let p = NodePointer._cache.get(key);
|
||||||
|
if (!p) {
|
||||||
|
p = new NodePointer(device_id, inode);
|
||||||
|
NodePointer._cache.set(key, p);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse(s: string): NodePointer {
|
static parse(s: string): NodePointer {
|
||||||
const m = /^(\d+):(\d+)$/.exec(s);
|
const m = /^(\d+):(\d+)$/.exec(s);
|
||||||
if (!m) throw new Error(`Invalid NodePointer: ${s}`);
|
if (!m) throw new Error(`Invalid NodePointer: ${s}`);
|
||||||
return new NodePointer(Number(m[1]), Number(m[2]));
|
let p = NodePointer._cache.get(s);
|
||||||
|
if (!p) {
|
||||||
|
p = new NodePointer(Number(m[1]), Number(m[2]));
|
||||||
|
NodePointer._cache.set(s, p);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
get device(): number {
|
get device(): number {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ export function resolvePointer(state: ShellState, pointer: NodePointer): string
|
|||||||
|
|
||||||
let ptr = pointer;
|
let ptr = pointer;
|
||||||
// TODO: Change while statements condition to not be hardcoded
|
// TODO: Change while statements condition to not be hardcoded
|
||||||
while (ptr.equals(NodePointer.of(0, 0))) {
|
while (!ptr.equals(NodePointer.of(0, 0))) {
|
||||||
if (state.filesystem.isMountTarget(ptr)) {
|
if (state.filesystem.isMountTarget(ptr)) {
|
||||||
const mount = state.filesystem.getMountPoint(ptr);
|
const mount = state.filesystem.getMountPoint(ptr);
|
||||||
if (!mount) {
|
if (!mount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user