minor: inline some library functions

This commit is contained in:
Fabian 2025-04-07 19:43:58 +07:00
parent 51bd604cc5
commit 3bb724fa69
3 changed files with 7 additions and 16 deletions

View file

@ -4,12 +4,10 @@
// Implementation of the 9p filesystem device following the
// 9P2000.L protocol ( https://code.google.com/p/diod/wiki/protocol )
import { LOG_9P } from "./../src/const.js";
import { VirtIO, VIRTIO_F_VERSION_1, VIRTIO_F_RING_EVENT_IDX, VIRTIO_F_RING_INDIRECT_DESC } from "../src/virtio.js";
import { S_IFREG, S_IFDIR, STATUS_UNLINKED } from "./filesystem.js";
import * as marshall from "../lib/marshall.js";
import { range } from "../src/lib.js";
import { dbg_log, dbg_assert } from "../src/log.js";
import { h } from "../src/lib.js";
@ -84,6 +82,11 @@ var FID_NONE = -1;
var FID_INODE = 1;
var FID_XATTR = 2;
function range(size)
{
return Array.from(Array(size).keys());
}
/**
* @constructor
*

View file

@ -14,18 +14,6 @@ export function pad0(str, len)
return str.padStart(len, "0");
}
// generates array given size with zeros
export function zeros(size)
{
return Array(size).fill(0);
}
// generates [0, 1, 2, ..., size-1]
export function range(size)
{
return Array.from(Array(size).keys());
}
export var view = function(constructor, memory, offset, length)
{
dbg_assert(offset >= 0);

View file

@ -1,5 +1,5 @@
import { LOG_VIRTIO } from "./const.js";
import { h, zeros, int_log2 } from "./lib.js";
import { h, int_log2 } from "./lib.js";
import { dbg_assert, dbg_log } from "./log.js";
// For Types Only
@ -230,7 +230,7 @@ export function VirtIO(cpu, options)
];
// Prevent sparse arrays by preallocating.
this.pci_space = this.pci_space.concat(zeros(256 - this.pci_space.length));
this.pci_space = this.pci_space.concat(Array(256 - this.pci_space.length).fill(0));
// Remaining PCI space is appended by capabilities further below.
this.pci_id = options.pci_id;