pxt-common-packages 13.2.5 → 13.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/base/pxtbase.h +17 -1
- package/package.json +1 -1
package/libs/base/pxtbase.h
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
#include <string.h>
|
|
48
48
|
#include <stdint.h>
|
|
49
|
+
#include <stddef.h> // offsetof
|
|
49
50
|
#include <math.h>
|
|
50
51
|
|
|
51
52
|
#ifdef POKY
|
|
@@ -552,7 +553,22 @@ class Segment {
|
|
|
552
553
|
TValue get(unsigned i) { return i < length ? data[i] : NULL; }
|
|
553
554
|
void set(unsigned i, TValue value);
|
|
554
555
|
|
|
555
|
-
unsigned getLength() {
|
|
556
|
+
unsigned getLength() {
|
|
557
|
+
// Layout pinned for the PXT compiler's Array.length fast path
|
|
558
|
+
// (_pxt_array_length_tagged in pxt/pxtcompiler/emitter/backthumb.ts).
|
|
559
|
+
// That fast path reads the element count directly out of the array
|
|
560
|
+
// object at a fixed byte offset instead of calling Array_::length:
|
|
561
|
+
// array object[0] = RefObject.vtable
|
|
562
|
+
// array object[sizeof(void*)] = RefCollection.head (this Segment)
|
|
563
|
+
// head[sizeof(TValue*)] = Segment.length
|
|
564
|
+
// so the length lives at object offset 2*sizeof(void*) == 8 on the
|
|
565
|
+
// 32-bit thumb target, read there as `ldrh r0, [r0, #8]`. If these
|
|
566
|
+
// structs are reordered, the offset in backthumb.ts must change too;
|
|
567
|
+
// these asserts fail the native build if that ever drifts.
|
|
568
|
+
STATIC_ASSERT(sizeof(RefObject) == sizeof(void *));
|
|
569
|
+
STATIC_ASSERT(offsetof(Segment, length) == sizeof(TValue *));
|
|
570
|
+
return length;
|
|
571
|
+
};
|
|
556
572
|
void setLength(unsigned newLength);
|
|
557
573
|
|
|
558
574
|
void push(TValue value) { set(length, value); }
|