Improve performance by not reading file data ahead of time

This commit is contained in:
Jordan Goulder 2025-01-17 21:26:51 -05:00
parent ee36f7a353
commit 0abcbc0d8c
3 changed files with 8 additions and 12 deletions

View File

@ -16,7 +16,7 @@ const fileListing = computed(() => {
<template> <template>
<section v-if="floppyDisk.bootSectorInfo"> <section v-if="floppyDisk.bootSectorInfo">
<h3>File Listing</h3> <h3>File Listing</h3>
<div v-html="fileListing"></div> <div v-memo="fileListing" v-html="fileListing"></div>
<h3>Boot Sector</h3> <h3>Boot Sector</h3>
<pre>{{ floppyDisk.bootSectorInfo }}</pre> <pre>{{ floppyDisk.bootSectorInfo }}</pre>
<h3>Directory Entries</h3> <h3>Directory Entries</h3>

View File

@ -19,6 +19,7 @@ function onReadStart(name: string) {
diskName.value = name diskName.value = name
diskReadBytes.value = 0 diskReadBytes.value = 0
diskTotalBytes.value = -1 diskTotalBytes.value = -1
diskData.value = new ArrayBuffer(0)
} }
function onReadSuccess(data: ArrayBuffer) { function onReadSuccess(data: ArrayBuffer) {

View File

@ -47,7 +47,6 @@ export interface IStandardDirEntry {
size: number size: number
firstCluster: number firstCluster: number
clusterChain: number[] clusterChain: number[]
data: ArrayBuffer
subDirEntries: TDirEntry[] subDirEntries: TDirEntry[]
} }
@ -174,6 +173,10 @@ export class FloppyDisk {
} }
clusterChain(start: number): number[] { clusterChain(start: number): number[] {
if (start < 2) {
return []
}
const chain = [start] const chain = [start]
let next = this.nextCluster(start) let next = this.nextCluster(start)
@ -337,15 +340,11 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
attributes, attributes,
firstCluster, firstCluster,
clusterChain: [], clusterChain: [],
data: new Uint8Array(0),
size, size,
subDirEntries: [], subDirEntries: [],
} }
if ( if (entry.attributes.directory && entry.name !== '.' && entry.name !== '..') {
entry.size > 0 ||
(entry.attributes.directory && entry.name !== '.' && entry.name !== '..')
) {
entry.clusterChain = fd.clusterChain(entry.firstCluster) entry.clusterChain = fd.clusterChain(entry.firstCluster)
const dataSize = entry.clusterChain.length * fd.bytesPerCluster const dataSize = entry.clusterChain.length * fd.bytesPerCluster
@ -360,11 +359,7 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
const resizedData = entryData.slice(0, entry.size > 0 ? entry.size : entryData.byteLength) const resizedData = entryData.slice(0, entry.size > 0 ? entry.size : entryData.byteLength)
if (entry.attributes.directory) { entry.subDirEntries = decodeDirectoryEntries(new DataView(resizedData.buffer), fd)
entry.subDirEntries = decodeDirectoryEntries(new DataView(resizedData.buffer), fd)
} else {
entry.data = resizedData
}
} }
} }