Skip to content

Commit d4b0afe

Browse files
committed
pre-format
1 parent a463dd1 commit d4b0afe

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

generators/async-file-system.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ function computeIsLittleEndian() {
3434
}
3535

3636
const isLittleEndian = computeIsLittleEndian();
37+
let globalCounter = 0;
3738

38-
function randomFileContents(bytes = ((Math.random() * 128) >>> 0) + 2056) {
39-
let result = new ArrayBuffer(bytes);
39+
function randomFileContents() {
40+
const numBytes = (globalCounter % 128) + 2056;
41+
globalCounter++;
42+
let result = new ArrayBuffer(numBytes);
4043
let view = new Uint8Array(result);
41-
for (let i = 0; i < bytes; ++i)
42-
view[i] = (Math.random() * 255) >>> 0;
44+
for (let i = 0; i < numBytes; ++i)
45+
view[i] = (i + globalCounter) % 255;
4346
return new DataView(result);
4447
}
4548

@@ -112,7 +115,7 @@ class Directory {
112115
} else {
113116
yield item;
114117
}
115-
}
118+
}
116119
}
117120

118121
async* forEachDirectoryRecursively() {
@@ -124,7 +127,7 @@ class Directory {
124127
yield dirItem;
125128

126129
yield item;
127-
}
130+
}
128131
}
129132

130133
async fileCount() {
@@ -145,19 +148,22 @@ class Directory {
145148
async function setupDirectory() {
146149
const fs = new Directory;
147150
let dirs = [fs];
151+
let counter = 0;
148152
for (let dir of dirs) {
149-
for (let i = 0; i < 8; ++i) {
150-
if (dirs.length < 250 && Math.random() >= 0.3) {
153+
for (let i = 0; i < 10; ++i) {
154+
if (dirs.length < 400 && (counter % 3) <= 1) {
151155
dirs.push(await dir.addDirectory(`dir-${i}`));
152156
}
157+
counter++;
153158
}
154159
}
155160

156161
for (let dir of dirs) {
157162
for (let i = 0; i < 5; ++i) {
158-
if (Math.random() >= 0.6) {
163+
if ((counter % 3) === 0) {
159164
await dir.addFile(`file-${i}`, new File(randomFileContents()));
160165
}
166+
counter++;
161167
}
162168
}
163169

@@ -178,7 +184,6 @@ class Benchmark {
178184
let result = await dir.rm(name);
179185
if (!result)
180186
throw new Error("rm should have returned true");
181-
182187
}
183188
}
184189
}

0 commit comments

Comments
 (0)