Skip to content

Commit 3761919

Browse files
committed
account for #1121
1 parent 9141f42 commit 3761919

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

std/assembly/staticarray.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ export class StaticArray<T> {
1919
static fromArray<T>(source: Array<T>): StaticArray<T> {
2020
var length = source.length;
2121
var outSize = <usize>length << alignof<T>();
22-
var out = __alloc(outSize, idof<StaticArray<T>>());
22+
var outPtr = __alloc(outSize, idof<StaticArray<T>>());
23+
var srcPtr = load<usize>(changetype<usize>(source), offsetof<Array<T>>("dataStart"));
2324
if (isManaged<T>()) {
24-
let sourcePtr = source.dataStart;
2525
for (let i = 0; i < length; ++i) {
2626
let off = <usize>i << alignof<T>();
27-
store<usize>(out + off, __retain(load<usize>(sourcePtr + off)));
27+
store<usize>(outPtr + off, __retain(load<usize>(srcPtr + off)));
2828
}
2929
} else {
30-
memory.copy(out, source.dataStart, outSize);
30+
memory.copy(outPtr, srcPtr, outSize);
3131
}
32-
return changetype<StaticArray<T>>(out);
32+
return changetype<StaticArray<T>>(outPtr);
3333
}
3434

3535
static concat<T>(source: StaticArray<T>, other: StaticArray<T>): StaticArray<T> {
3636
var sourceLen = source.length;
37-
var otherLen = select(0, other.length, other === null);
37+
var otherLen = select(0, other.length, changetype<usize>(other) == 0);
3838
var outLen = sourceLen + otherLen;
3939
if (<u32>outLen > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new Error(E_INVALIDLENGTH);
4040
var out = changetype<StaticArray<T>>(__alloc(<usize>outLen << alignof<T>(), idof<StaticArray<T>>())); // retains
@@ -166,28 +166,28 @@ export class StaticArray<T> {
166166

167167
concat(other: Array<T>): Array<T> {
168168
var thisLen = this.length;
169-
var otherLen = select(0, other.length, other === null);
169+
var otherLen = select(0, other.length, changetype<usize>(other) == 0);
170170
var outLen = thisLen + otherLen;
171171
if (<u32>outLen > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new Error(E_INVALIDLENGTH);
172172
var out = changetype<Array<T>>(__allocArray(outLen, alignof<T>(), idof<Array<T>>())); // retains
173-
var outStart = out.dataStart;
173+
var outPtr = load<usize>(changetype<usize>(out), offsetof<Array<T>>("dataStart"));
174+
var otherPtr = load<usize>(changetype<usize>(other), offsetof<Array<T>>("dataStart"));
174175
var thisSize = <usize>thisLen << alignof<T>();
175176
if (isManaged<T>()) {
176177
let thisStart = changetype<usize>(this);
177178
for (let offset: usize = 0; offset < thisSize; offset += sizeof<T>()) {
178179
let ref = load<usize>(thisStart + offset);
179-
store<usize>(outStart + offset, __retain(ref));
180+
store<usize>(outPtr + offset, __retain(ref));
180181
}
181-
outStart += thisSize;
182-
let otherStart = other.dataStart;
182+
outPtr += thisSize;
183183
let otherSize = <usize>otherLen << alignof<T>();
184184
for (let offset: usize = 0; offset < otherSize; offset += sizeof<T>()) {
185-
let ref = load<usize>(otherStart + offset);
186-
store<usize>(outStart + offset, __retain(ref));
185+
let ref = load<usize>(otherPtr + offset);
186+
store<usize>(outPtr + offset, __retain(ref));
187187
}
188188
} else {
189-
memory.copy(outStart, changetype<usize>(this), thisSize);
190-
memory.copy(outStart + thisSize, other.dataStart, <usize>otherLen << alignof<T>());
189+
memory.copy(outPtr, changetype<usize>(this), thisSize);
190+
memory.copy(outPtr + thisSize, otherPtr, <usize>otherLen << alignof<T>());
191191
}
192192
return out;
193193
}
@@ -198,18 +198,18 @@ export class StaticArray<T> {
198198
end = end < 0 ? max(end + length, 0) : min(end , length);
199199
length = max(end - start, 0);
200200
var slice = changetype<Array<T>>(__allocArray(length, alignof<T>(), idof<Array<T>>())); // retains
201-
var sliceBase = slice.dataStart;
202-
var thisBase = changetype<usize>(this) + (<usize>start << alignof<T>());
201+
var slicePtr = load<usize>(changetype<usize>(slice), offsetof<Array<T>>("dataStart"));
202+
var thisPtr = changetype<usize>(this) + (<usize>start << alignof<T>());
203203
if (isManaged<T>()) {
204204
let off = <usize>0;
205205
let end = <usize>length << alignof<usize>();
206206
while (off < end) {
207-
let ref = load<usize>(thisBase + off);
208-
store<usize>(sliceBase + off, __retain(ref));
207+
let ref = load<usize>(thisPtr + off);
208+
store<usize>(slicePtr + off, __retain(ref));
209209
off += sizeof<usize>();
210210
}
211211
} else {
212-
memory.copy(sliceBase, thisBase, length << alignof<T>());
212+
memory.copy(slicePtr, thisPtr, length << alignof<T>());
213213
}
214214
return slice;
215215
}

std/assembly/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Array } from "./array";
2222
static fromCharCodes(units: Array<i32>): String {
2323
var length = units.length;
2424
var out = __alloc(<usize>length << 1, idof<String>());
25-
var ptr = units.dataStart;
25+
var ptr = load<usize>(changetype<usize>(units), offsetof<Array<i32>>("dataStart"));
2626
for (let i = 0; i < length; ++i) {
2727
store<u16>(out + (<usize>i << 1), load<i32>(ptr + (<usize>i << 2)));
2828
}

0 commit comments

Comments
 (0)