Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Optimize] memory.copy parameters with global strings
  • Loading branch information
jtenner committed Jul 23, 2019
commit f418fd039eea0e51a0d679eb46c3f31405973274
10 changes: 6 additions & 4 deletions assembly/buffer/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BLOCK_MAXSIZE } from "rt/common";
import { BLOCK_MAXSIZE, BLOCK, BLOCK_OVERHEAD } from "rt/common";
import { E_INVALIDLENGTH, E_INDEXOUTOFRANGE } from "util/error";
import { Uint8Array } from "typedarray";

const BUFFER_INSPECT_HEADER_START: string = "<Buffer ";

export let INSPECT_MAX_BYTES: i32 = 50;
Expand Down Expand Up @@ -73,8 +72,11 @@ export class Buffer extends Uint8Array {
let result = __alloc(stringLength << 1, idof<String>());

// copy the 16 "<Buffer " bytes
let source = "<Buffer ";
memory.copy(result, changetype<usize>(source), 16);
memory.copy(
result,
changetype<usize>(BUFFER_INSPECT_HEADER_START),
changetype<BLOCK>(changetype<usize>(BUFFER_INSPECT_HEADER_START) - BLOCK_OVERHEAD).rtSize,
);

// Start writing at index 8
let writeOffset: usize = result + 16;
Expand Down
4 changes: 1 addition & 3 deletions tests/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ function runTest(file, type, binary, wat) {
+ "." + type + ".wat";

// should not block testing
fs.writeFile(watPath, wat, (err) => {
if (err) console.warn(err);
});
fs.writeFileSync(watPath, wat);

const context = new TestContext({
fileName: file,
Expand Down