Float32ArrayDefault class final
The declared default of an fp32 array field, prepared once so that the test "does this field still equal its default" costs a plain element loop.
A generated class holds one per defaulted field in a static final, fills
the field's storage from list (InlineFloat32Array.assign) and asks
matches on every encode (MESSAGE_SPEC §2, §5.1: a field is written only
when it differs from its default).
matches is floatBitsEqual on the field's first length elements against
list, bit for bit: +0.0 differs from -0.0, a NaN equals a NaN of
identical bits, the length is compared first. What makes it cheap is that the
default is a constant. Two doubles that compare == have the same bits unless
both are zero, and which indices of the default are zero is known here, once.
So matches runs one != loop over the elements (a NaN in the field is a
mismatch, since the default holds none), split at the first zero index: the
element there is read once, by the loop, and its sign tested on the spot.
Further zeros, and a default that holds a NaN (whose != always fails), are
the rare cases and are settled out of line.
Constructors
-
Float32ArrayDefault(List<
double> values) -
A typed copy of
valueswith the zero and NaN positions noted.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- list → Float32List
-
The default itself, for filling a field's storage.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
matches(
Float32List a, int n) → bool -
Whether the first
nelements ofaare, bit for bit, this default.nmust not exceeda.length(an index past it throws, as on any typed list). A length mismatch reads no element; there is no allocation, and no mutation, unless the default holds a NaN. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited