[vm] Recognize unmodifiable typed data views.
These types now work with Dart_TypedDataAcquireData. The presence of these types no longer degrades the performance of typed data indexed loads. The presence of these types degrades the performance of typed data indexed stores much less. The performance of indexed stores is somewhat regressed if these types were not used. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/32028 Bug: https://github.com/dart-lang/sdk/issues/40924 Bug: https://github.com/dart-lang/sdk/issues/42785 Change-Id: Iffad865708501acf96db418985cd5a69bd9afa55 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254501 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
@@ -94,6 +94,7 @@ static bool IsClamped(intptr_t cid) {
|
||||
case kTypedDataUint8ClampedArrayCid:
|
||||
case kExternalTypedDataUint8ClampedArrayCid:
|
||||
case kTypedDataUint8ClampedArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -105,9 +106,11 @@ static bool IsUint8(intptr_t cid) {
|
||||
case kTypedDataUint8ClampedArrayCid:
|
||||
case kExternalTypedDataUint8ClampedArrayCid:
|
||||
case kTypedDataUint8ClampedArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
|
||||
case kTypedDataUint8ArrayCid:
|
||||
case kExternalTypedDataUint8ArrayCid:
|
||||
case kTypedDataUint8ArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint8ArrayViewCid:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -186,10 +189,15 @@ static InstancePtr NewTypedDataView(intptr_t cid,
|
||||
}
|
||||
|
||||
#define TYPED_DATA_NEW_NATIVE(name) \
|
||||
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, kTypedData##name##ViewCid)
|
||||
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, \
|
||||
kTypedData##name##ViewCid) \
|
||||
TYPED_DATA_VIEW_NEW(TypedDataView_Unmodifiable##name##View_new, \
|
||||
kUnmodifiableTypedData##name##ViewCid)
|
||||
|
||||
CLASS_LIST_TYPED_DATA(TYPED_DATA_NEW_NATIVE)
|
||||
TYPED_DATA_VIEW_NEW(TypedDataView_ByteDataView_new, kByteDataViewCid)
|
||||
TYPED_DATA_VIEW_NEW(TypedDataView_UnmodifiableByteDataView_new,
|
||||
kUnmodifiableByteDataViewCid)
|
||||
#undef TYPED_DATA_NEW_NATIVE
|
||||
#undef TYPED_DATA_VIEW_NEW
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// This test asserts that we are not inlining accesses to typed data interfaces
|
||||
// (e.g. Uint8List) if there are instantiated 3rd party classes (e.g.
|
||||
// UnmodifiableUint8ListView).
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'package:vm/testing/il_matchers.dart';
|
||||
|
||||
createThirdPartyUint8List() => UnmodifiableUint8ListView(Uint8List(10));
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
@pragma('vm:testing:print-flow-graph')
|
||||
void foo(Uint8List list, int from) {
|
||||
if (from >= list.length) {
|
||||
list[from];
|
||||
}
|
||||
}
|
||||
|
||||
void matchIL$foo(FlowGraph graph) {
|
||||
graph.match([
|
||||
match.block('Graph'),
|
||||
match.block('Function', [
|
||||
'list' << match.Parameter(index: 0),
|
||||
'from' << match.Parameter(index: 1),
|
||||
'v13' << match.LoadClassId('list'),
|
||||
match.PushArgument('list'),
|
||||
match.DispatchTableCall('v13', selector_name: 'get:length'),
|
||||
match.Branch(match.RelationalOp(match.any, match.any, kind: '>='),
|
||||
ifTrue: 'B3'),
|
||||
]),
|
||||
'B3' <<
|
||||
match.block('Target', [
|
||||
'v15' << match.LoadClassId('list'),
|
||||
match.PushArgument('list'),
|
||||
match.PushArgument(/* BoxInt64(Parameter) or Parameter */),
|
||||
match.DispatchTableCall('v15', selector_name: '[]'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
void main() {
|
||||
foo(int.parse('1') == 1 ? createThirdPartyUint8List() : Uint8List(1),
|
||||
int.parse('0'));
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// This test asserts that we are not inlining accesses to typed data interfaces
|
||||
// (e.g. Uint8List) if there are instantiated 3rd party classes (e.g.
|
||||
// UnmodifiableUint8ListView).
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'package:vm/testing/il_matchers.dart';
|
||||
|
||||
createThirdPartyUint8List() => UnmodifiableUint8ListView(Uint8List(10));
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
@pragma('vm:testing:print-flow-graph')
|
||||
void foo(Uint8List list, int from) {
|
||||
if (from >= list.length) {
|
||||
list[from];
|
||||
}
|
||||
}
|
||||
|
||||
void matchIL$foo(FlowGraph graph) {
|
||||
graph.match([
|
||||
match.block('Graph'),
|
||||
match.block('Function', [
|
||||
'list' << match.Parameter(index: 0),
|
||||
'from' << match.Parameter(index: 1),
|
||||
'v13' << match.LoadClassId('list'),
|
||||
match.PushArgument('list'),
|
||||
match.DispatchTableCall('v13', selector_name: 'get:length'),
|
||||
match.Branch(match.RelationalOp(match.any, match.any, kind: '>='),
|
||||
ifTrue: 'B3'),
|
||||
]),
|
||||
'B3' <<
|
||||
match.block('Target', [
|
||||
'v15' << match.LoadClassId('list'),
|
||||
match.PushArgument('list'),
|
||||
match.PushArgument(/* BoxInt64(Parameter) or Parameter */),
|
||||
match.DispatchTableCall('v15', selector_name: '[]'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
void main() {
|
||||
foo(int.parse('1') == 1 ? createThirdPartyUint8List() : Uint8List(1),
|
||||
int.parse('0'));
|
||||
}
|
||||
@@ -217,6 +217,21 @@ namespace dart {
|
||||
V(TypedDataView_Float64x2ArrayView_new, 4) \
|
||||
V(TypedDataView_offsetInBytes, 1) \
|
||||
V(TypedDataView_typedData, 1) \
|
||||
V(TypedDataView_UnmodifiableByteDataView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableInt8ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableUint8ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableUint8ClampedArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableInt16ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableUint16ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableInt32ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableUint32ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableInt64ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableUint64ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableFloat32ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableFloat64ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableFloat32x4ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableInt32x4ArrayView_new, 4) \
|
||||
V(TypedDataView_UnmodifiableFloat64x2ArrayView_new, 4) \
|
||||
V(Float32x4_fromDoubles, 4) \
|
||||
V(Float32x4_splat, 1) \
|
||||
V(Float32x4_fromInt32x4Bits, 2) \
|
||||
|
||||
+36
-22
@@ -233,10 +233,12 @@ enum ClassId : intptr_t {
|
||||
#define DEFINE_OBJECT_KIND(clazz) \
|
||||
kTypedData##clazz##Cid, \
|
||||
kTypedData##clazz##ViewCid, \
|
||||
kExternalTypedData##clazz##Cid,
|
||||
kExternalTypedData##clazz##Cid, \
|
||||
kUnmodifiableTypedData##clazz##ViewCid,
|
||||
CLASS_LIST_TYPED_DATA(DEFINE_OBJECT_KIND)
|
||||
#undef DEFINE_OBJECT_KIND
|
||||
kByteDataViewCid,
|
||||
kUnmodifiableByteDataViewCid,
|
||||
|
||||
kByteBufferCid,
|
||||
// clang-format on
|
||||
@@ -255,6 +257,7 @@ enum ClassId : intptr_t {
|
||||
const int kTypedDataCidRemainderInternal = 0;
|
||||
const int kTypedDataCidRemainderView = 1;
|
||||
const int kTypedDataCidRemainderExternal = 2;
|
||||
const int kTypedDataCidRemainderUnmodifiable = 3;
|
||||
|
||||
// Class Id predicates.
|
||||
|
||||
@@ -361,34 +364,45 @@ inline bool IsTypeClassId(intptr_t index) {
|
||||
|
||||
inline bool IsTypedDataBaseClassId(intptr_t index) {
|
||||
// Make sure this is updated when new TypedData types are added.
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 == kTypedDataUint8ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 == kTypedDataUint8ArrayCid);
|
||||
return index >= kTypedDataInt8ArrayCid && index < kByteDataViewCid;
|
||||
}
|
||||
|
||||
inline bool IsTypedDataClassId(intptr_t index) {
|
||||
// Make sure this is updated when new TypedData types are added.
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 == kTypedDataUint8ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 == kTypedDataUint8ArrayCid);
|
||||
return IsTypedDataBaseClassId(index) && ((index - kTypedDataInt8ArrayCid) %
|
||||
3) == kTypedDataCidRemainderInternal;
|
||||
4) == kTypedDataCidRemainderInternal;
|
||||
}
|
||||
|
||||
inline bool IsTypedDataViewClassId(intptr_t index) {
|
||||
// Make sure this is updated when new TypedData types are added.
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayViewCid + 3 == kTypedDataUint8ArrayViewCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayViewCid + 4 == kTypedDataUint8ArrayViewCid);
|
||||
|
||||
const bool is_byte_data_view = index == kByteDataViewCid;
|
||||
return is_byte_data_view ||
|
||||
(IsTypedDataBaseClassId(index) &&
|
||||
((index - kTypedDataInt8ArrayCid) % 3) == kTypedDataCidRemainderView);
|
||||
((index - kTypedDataInt8ArrayCid) % 4) == kTypedDataCidRemainderView);
|
||||
}
|
||||
|
||||
inline bool IsExternalTypedDataClassId(intptr_t index) {
|
||||
// Make sure this is updated when new TypedData types are added.
|
||||
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 3 ==
|
||||
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 4 ==
|
||||
kExternalTypedDataUint8ArrayCid);
|
||||
|
||||
return IsTypedDataBaseClassId(index) && ((index - kTypedDataInt8ArrayCid) %
|
||||
3) == kTypedDataCidRemainderExternal;
|
||||
4) == kTypedDataCidRemainderExternal;
|
||||
}
|
||||
|
||||
inline bool IsUnmodifiableTypedDataViewClassId(intptr_t index) {
|
||||
// Make sure this is updated when new TypedData types are added.
|
||||
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 4 ==
|
||||
kExternalTypedDataUint8ArrayCid);
|
||||
|
||||
const bool is_byte_data_view = index == kUnmodifiableByteDataViewCid;
|
||||
return is_byte_data_view || (IsTypedDataBaseClassId(index) &&
|
||||
((index - kTypedDataInt8ArrayCid) % 4) ==
|
||||
kTypedDataCidRemainderUnmodifiable);
|
||||
}
|
||||
|
||||
inline bool IsFfiTypeClassId(intptr_t index) {
|
||||
@@ -446,21 +460,21 @@ COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 == kTypedDataInt8ArrayViewCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 == kExternalTypedDataInt8ArrayCid);
|
||||
|
||||
// Ensure the order of the typed data members in 3-step.
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 3 == kTypedDataUint8ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 3 ==
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 4 == kTypedDataUint8ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 4 ==
|
||||
kTypedDataUint8ClampedArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 3 == kTypedDataInt16ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 3 == kTypedDataUint16ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 3 == kTypedDataInt32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 3 == kTypedDataUint32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 3 == kTypedDataInt64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 3 == kTypedDataUint64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 3 == kTypedDataFloat32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 3 == kTypedDataFloat64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 3 == kTypedDataFloat32x4ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 3 == kTypedDataInt32x4ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 3 == kTypedDataFloat64x2ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 3 == kByteDataViewCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 4 == kTypedDataInt16ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 4 == kTypedDataUint16ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 4 == kTypedDataInt32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 4 == kTypedDataUint32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 4 == kTypedDataInt64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 4 == kTypedDataUint64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 4 == kTypedDataFloat32ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 4 == kTypedDataFloat64ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 4 == kTypedDataFloat32x4ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 4 == kTypedDataInt32x4ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 4 == kTypedDataFloat64x2ArrayCid);
|
||||
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 4 == kByteDataViewCid);
|
||||
COMPILE_ASSERT(kByteBufferCid + 1 == kNullCid);
|
||||
|
||||
} // namespace dart
|
||||
|
||||
@@ -409,6 +409,13 @@ void ConstantPropagator::VisitGenericCheckBound(GenericCheckBoundInstr* instr) {
|
||||
SetValue(instr, non_constant_);
|
||||
}
|
||||
|
||||
void ConstantPropagator::VisitCheckWritable(CheckWritableInstr* instr) {
|
||||
// Don't propagate constants through check, since it would eliminate
|
||||
// the data dependence between the writable check and its use.
|
||||
// Graph finalization will expose the constant eventually.
|
||||
SetValue(instr, non_constant_);
|
||||
}
|
||||
|
||||
void ConstantPropagator::VisitCheckNull(CheckNullInstr* instr) {
|
||||
// Don't propagate constants through check, since it would eliminate
|
||||
// the data dependence between the null check and its use.
|
||||
|
||||
@@ -3405,6 +3405,36 @@ void RangeErrorSlowPath::PushArgumentsForRuntimeCall(
|
||||
locs->in(CheckBoundBase::kLengthPos).reg());
|
||||
}
|
||||
|
||||
void RangeErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
|
||||
bool save_fpu_registers) {
|
||||
#if defined(TARGET_ARCH_IA32)
|
||||
UNREACHABLE();
|
||||
#else
|
||||
auto object_store = compiler->isolate_group()->object_store();
|
||||
const auto& stub = Code::ZoneHandle(
|
||||
compiler->zone(),
|
||||
save_fpu_registers
|
||||
? object_store->range_error_stub_with_fpu_regs_stub()
|
||||
: object_store->range_error_stub_without_fpu_regs_stub());
|
||||
compiler->EmitCallToStub(stub);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WriteErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
|
||||
bool save_fpu_registers) {
|
||||
#if defined(TARGET_ARCH_IA32)
|
||||
UNREACHABLE();
|
||||
#else
|
||||
auto object_store = compiler->isolate_group()->object_store();
|
||||
const auto& stub = Code::ZoneHandle(
|
||||
compiler->zone(),
|
||||
save_fpu_registers
|
||||
? object_store->write_error_stub_with_fpu_regs_stub()
|
||||
: object_store->write_error_stub_without_fpu_regs_stub());
|
||||
compiler->EmitCallToStub(stub);
|
||||
#endif
|
||||
}
|
||||
|
||||
void LateInitializationErrorSlowPath::PushArgumentsForRuntimeCall(
|
||||
FlowGraphCompiler* compiler) {
|
||||
__ PushObject(Field::ZoneHandle(OriginalField()));
|
||||
|
||||
@@ -386,6 +386,16 @@ class RangeErrorSlowPath : public ThrowErrorSlowPathCode {
|
||||
bool save_fpu_registers);
|
||||
};
|
||||
|
||||
class WriteErrorSlowPath : public ThrowErrorSlowPathCode {
|
||||
public:
|
||||
explicit WriteErrorSlowPath(CheckWritableInstr* instruction)
|
||||
: ThrowErrorSlowPathCode(instruction, kWriteErrorRuntimeEntry) {}
|
||||
virtual const char* name() { return "check writable"; }
|
||||
|
||||
virtual void EmitSharedStubCall(FlowGraphCompiler* compiler,
|
||||
bool save_fpu_registers);
|
||||
};
|
||||
|
||||
class LateInitializationErrorSlowPath : public ThrowErrorSlowPathCode {
|
||||
public:
|
||||
explicit LateInitializationErrorSlowPath(Instruction* instruction)
|
||||
|
||||
@@ -538,6 +538,10 @@ Value* CheckBoundBase::RedefinedValue() const {
|
||||
return index();
|
||||
}
|
||||
|
||||
Value* CheckWritableInstr::RedefinedValue() const {
|
||||
return value();
|
||||
}
|
||||
|
||||
Value* CheckNullInstr::RedefinedValue() const {
|
||||
return value();
|
||||
}
|
||||
@@ -2617,6 +2621,31 @@ bool LoadFieldInstr::IsTypedDataViewFactory(const Function& function) {
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadFieldInstr::IsUnmodifiableTypedDataViewFactory(
|
||||
const Function& function) {
|
||||
auto kind = function.recognized_kind();
|
||||
switch (kind) {
|
||||
case MethodRecognizer::kTypedData_UnmodifiableByteDataView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt8ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint8ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint8ClampedArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt16ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint16ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat64x2ArrayView_factory:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Definition* ConstantInstr::Canonicalize(FlowGraph* flow_graph) {
|
||||
return HasUses() ? this : NULL;
|
||||
}
|
||||
@@ -2767,7 +2796,8 @@ Definition* LoadFieldInstr::Canonicalize(FlowGraph* flow_graph) {
|
||||
ASSERT(!calls_initializer());
|
||||
Definition* array = instance()->definition()->OriginalDefinition();
|
||||
if (StaticCallInstr* call = array->AsStaticCall()) {
|
||||
if (IsTypedDataViewFactory(call->function())) {
|
||||
if (IsTypedDataViewFactory(call->function()) ||
|
||||
IsUnmodifiableTypedDataViewFactory(call->function())) {
|
||||
return call->ArgumentAt(1);
|
||||
}
|
||||
}
|
||||
@@ -2792,7 +2822,8 @@ Definition* LoadFieldInstr::Canonicalize(FlowGraph* flow_graph) {
|
||||
if (StaticCallInstr* call = array->AsStaticCall()) {
|
||||
if (call->is_known_list_constructor()) {
|
||||
return call->ArgumentAt(0);
|
||||
} else if (IsTypedDataViewFactory(call->function())) {
|
||||
} else if (IsTypedDataViewFactory(call->function()) ||
|
||||
IsUnmodifiableTypedDataViewFactory(call->function())) {
|
||||
return flow_graph->constant_null();
|
||||
}
|
||||
switch (call->function().recognized_kind()) {
|
||||
@@ -5762,20 +5793,6 @@ void DoubleToIntegerSlowPath::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
__ Jump(exit_label());
|
||||
}
|
||||
|
||||
void RangeErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
|
||||
bool save_fpu_registers) {
|
||||
#if defined(TARGET_ARCH_IA32)
|
||||
UNREACHABLE();
|
||||
#else
|
||||
auto object_store = compiler->isolate_group()->object_store();
|
||||
const auto& stub = Code::ZoneHandle(
|
||||
compiler->zone(),
|
||||
save_fpu_registers
|
||||
? object_store->range_error_stub_with_fpu_regs_stub()
|
||||
: object_store->range_error_stub_without_fpu_regs_stub());
|
||||
compiler->EmitCallToStub(stub);
|
||||
#endif
|
||||
}
|
||||
|
||||
void UnboxInstr::EmitLoadFromBoxWithDeopt(FlowGraphCompiler* compiler) {
|
||||
const intptr_t box_cid = BoxCid();
|
||||
@@ -6154,6 +6171,7 @@ Definition* CheckBoundBase::Canonicalize(FlowGraph* flow_graph) {
|
||||
|
||||
intptr_t CheckArrayBoundInstr::LengthOffsetFor(intptr_t class_id) {
|
||||
if (IsTypedDataClassId(class_id) || IsTypedDataViewClassId(class_id) ||
|
||||
IsUnmodifiableTypedDataViewClassId(class_id) ||
|
||||
IsExternalTypedDataClassId(class_id)) {
|
||||
return compiler::target::TypedDataBase::length_offset();
|
||||
}
|
||||
@@ -6173,6 +6191,15 @@ intptr_t CheckArrayBoundInstr::LengthOffsetFor(intptr_t class_id) {
|
||||
}
|
||||
}
|
||||
|
||||
Definition* CheckWritableInstr::Canonicalize(FlowGraph* flow_graph) {
|
||||
intptr_t cid = value()->Type()->ToCid();
|
||||
if ((cid != kIllegalCid) && (cid != kDynamicCid) &&
|
||||
!IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
return value()->definition();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
static AlignmentType StrengthenAlignment(intptr_t cid,
|
||||
AlignmentType alignment) {
|
||||
switch (cid) {
|
||||
|
||||
@@ -500,6 +500,7 @@ struct InstrAttrs {
|
||||
M(UnaryInt64Op, kNoGC) \
|
||||
M(CheckArrayBound, kNoGC) \
|
||||
M(GenericCheckBound, kNoGC) \
|
||||
M(CheckWritable, kNoGC) \
|
||||
M(Constraint, kNoGC) \
|
||||
M(StringToCharCode, kNoGC) \
|
||||
M(OneByteStringFromCharCode, kNoGC) \
|
||||
@@ -6824,6 +6825,7 @@ class LoadFieldInstr : public TemplateLoadField<1> {
|
||||
|
||||
static bool IsFixedLengthArrayCid(intptr_t cid);
|
||||
static bool IsTypedDataViewFactory(const Function& function);
|
||||
static bool IsUnmodifiableTypedDataViewFactory(const Function& function);
|
||||
|
||||
virtual bool AllowsCSE() const { return slot_.is_immutable(); }
|
||||
|
||||
@@ -9104,6 +9106,31 @@ class GenericCheckBoundInstr : public CheckBoundBase {
|
||||
DISALLOW_COPY_AND_ASSIGN(GenericCheckBoundInstr);
|
||||
};
|
||||
|
||||
class CheckWritableInstr : public TemplateDefinition<1, Throws, Pure> {
|
||||
public:
|
||||
CheckWritableInstr(Value* array,
|
||||
intptr_t deopt_id,
|
||||
const InstructionSource& source)
|
||||
: TemplateDefinition(source, deopt_id) {
|
||||
SetInputAt(0, array);
|
||||
}
|
||||
|
||||
virtual bool AttributesEqual(const Instruction& other) const { return true; }
|
||||
|
||||
DECLARE_INSTRUCTION(CheckWritable)
|
||||
|
||||
Value* value() const { return inputs_[0]; }
|
||||
|
||||
virtual Definition* Canonicalize(FlowGraph* flow_graph);
|
||||
|
||||
virtual Value* RedefinedValue() const;
|
||||
|
||||
virtual bool ComputeCanDeoptimize() const { return false; }
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CheckWritableInstr);
|
||||
};
|
||||
|
||||
// Instruction evaluates the given comparison and deoptimizes if it evaluates
|
||||
// to false.
|
||||
class CheckConditionInstr : public Instruction {
|
||||
|
||||
@@ -6587,6 +6587,29 @@ void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
}
|
||||
}
|
||||
|
||||
LocationSummary* CheckWritableInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 1;
|
||||
const intptr_t kNumTemps = 0;
|
||||
LocationSummary* locs = new (zone) LocationSummary(
|
||||
zone, kNumInputs, kNumTemps,
|
||||
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
|
||||
: LocationSummary::kCallOnSlowPath);
|
||||
locs->set_in(0, Location::RequiresRegister());
|
||||
return locs;
|
||||
}
|
||||
|
||||
void CheckWritableInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
WriteErrorSlowPath* slow_path = new WriteErrorSlowPath(this);
|
||||
compiler->AddSlowPathCode(slow_path);
|
||||
__ ldrb(TMP, compiler::FieldAddress(locs()->in(0).reg(),
|
||||
compiler::target::Object::tags_offset()));
|
||||
// In the first byte.
|
||||
ASSERT(compiler::target::UntaggedObject::kImmutableBit < 8);
|
||||
__ TestImmediate(TMP, 1 << compiler::target::UntaggedObject::kImmutableBit);
|
||||
__ b(slow_path->entry_label(), NOT_ZERO);
|
||||
}
|
||||
|
||||
LocationSummary* BinaryInt64OpInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 2;
|
||||
|
||||
@@ -5649,6 +5649,32 @@ void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
}
|
||||
}
|
||||
|
||||
LocationSummary* CheckWritableInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 1;
|
||||
const intptr_t kNumTemps = 0;
|
||||
LocationSummary* locs = new (zone) LocationSummary(
|
||||
zone, kNumInputs, kNumTemps,
|
||||
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
|
||||
: LocationSummary::kCallOnSlowPath);
|
||||
locs->set_in(0, Location::RequiresRegister());
|
||||
return locs;
|
||||
}
|
||||
|
||||
void CheckWritableInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
WriteErrorSlowPath* slow_path = new WriteErrorSlowPath(this);
|
||||
compiler->AddSlowPathCode(slow_path);
|
||||
__ ldr(TMP,
|
||||
compiler::FieldAddress(locs()->in(0).reg(),
|
||||
compiler::target::Object::tags_offset(),
|
||||
compiler::kUnsignedByte),
|
||||
compiler::kUnsignedByte);
|
||||
// In the first byte.
|
||||
ASSERT(compiler::target::UntaggedObject::kImmutableBit < 8);
|
||||
__ tbnz(slow_path->entry_label(), TMP,
|
||||
compiler::target::UntaggedObject::kImmutableBit);
|
||||
}
|
||||
|
||||
class Int64DivideSlowPath : public ThrowErrorSlowPathCode {
|
||||
public:
|
||||
Int64DivideSlowPath(BinaryInt64OpInstr* instruction,
|
||||
|
||||
@@ -5713,6 +5713,28 @@ void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
}
|
||||
}
|
||||
|
||||
LocationSummary* CheckWritableInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 1;
|
||||
const intptr_t kNumTemps = 0;
|
||||
LocationSummary* locs = new (zone) LocationSummary(
|
||||
zone, kNumInputs, kNumTemps,
|
||||
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
|
||||
: LocationSummary::kCallOnSlowPath);
|
||||
locs->set_in(0, Location::RequiresRegister());
|
||||
return locs;
|
||||
}
|
||||
|
||||
void CheckWritableInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
WriteErrorSlowPath* slow_path = new WriteErrorSlowPath(this);
|
||||
compiler->AddSlowPathCode(slow_path);
|
||||
__ movl(TMP, compiler::FieldAddress(locs()->in(0).reg(),
|
||||
compiler::target::Object::tags_offset()));
|
||||
__ testl(TMP, compiler::Immediate(
|
||||
1 << compiler::target::UntaggedObject::kImmutableBit));
|
||||
__ j(NOT_ZERO, slow_path->entry_label());
|
||||
}
|
||||
|
||||
LocationSummary* BinaryInt64OpInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 2;
|
||||
|
||||
@@ -5803,6 +5803,29 @@ void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
}
|
||||
}
|
||||
|
||||
LocationSummary* CheckWritableInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 1;
|
||||
const intptr_t kNumTemps = 0;
|
||||
LocationSummary* locs = new (zone) LocationSummary(
|
||||
zone, kNumInputs, kNumTemps,
|
||||
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
|
||||
: LocationSummary::kCallOnSlowPath);
|
||||
locs->set_in(0, Location::RequiresRegister());
|
||||
return locs;
|
||||
}
|
||||
|
||||
void CheckWritableInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
WriteErrorSlowPath* slow_path = new WriteErrorSlowPath(this);
|
||||
compiler->AddSlowPathCode(slow_path);
|
||||
__ lbu(TMP, compiler::FieldAddress(locs()->in(0).reg(),
|
||||
compiler::target::Object::tags_offset()));
|
||||
// In the first byte.
|
||||
ASSERT(compiler::target::UntaggedObject::kImmutableBit < 8);
|
||||
__ andi(TMP, TMP, 1 << compiler::target::UntaggedObject::kImmutableBit);
|
||||
__ bnez(TMP, slow_path->entry_label());
|
||||
}
|
||||
|
||||
class Int64DivideSlowPath : public ThrowErrorSlowPathCode {
|
||||
public:
|
||||
Int64DivideSlowPath(BinaryInt64OpInstr* instruction,
|
||||
|
||||
@@ -5991,6 +5991,28 @@ void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
}
|
||||
}
|
||||
|
||||
LocationSummary* CheckWritableInstr::MakeLocationSummary(Zone* zone,
|
||||
bool opt) const {
|
||||
const intptr_t kNumInputs = 1;
|
||||
const intptr_t kNumTemps = 0;
|
||||
LocationSummary* locs = new (zone) LocationSummary(
|
||||
zone, kNumInputs, kNumTemps,
|
||||
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
|
||||
: LocationSummary::kCallOnSlowPath);
|
||||
locs->set_in(0, Location::RequiresRegister());
|
||||
return locs;
|
||||
}
|
||||
|
||||
void CheckWritableInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
WriteErrorSlowPath* slow_path = new WriteErrorSlowPath(this);
|
||||
compiler->AddSlowPathCode(slow_path);
|
||||
__ movq(TMP, compiler::FieldAddress(locs()->in(0).reg(),
|
||||
compiler::target::Object::tags_offset()));
|
||||
__ testq(TMP, compiler::Immediate(
|
||||
1 << compiler::target::UntaggedObject::kImmutableBit));
|
||||
__ j(NOT_ZERO, slow_path->entry_label());
|
||||
}
|
||||
|
||||
class Int64DivideSlowPath : public ThrowErrorSlowPathCode {
|
||||
public:
|
||||
Int64DivideSlowPath(BinaryInt64OpInstr* instruction,
|
||||
|
||||
@@ -268,7 +268,8 @@ bool Slot::IsImmutableLengthSlot() const {
|
||||
// Note: should only be called with cids of array-like classes.
|
||||
const Slot& Slot::GetLengthFieldForArrayCid(intptr_t array_cid) {
|
||||
if (IsExternalTypedDataClassId(array_cid) || IsTypedDataClassId(array_cid) ||
|
||||
IsTypedDataViewClassId(array_cid)) {
|
||||
IsTypedDataViewClassId(array_cid) ||
|
||||
IsUnmodifiableTypedDataViewClassId(array_cid)) {
|
||||
return GetNativeSlot(Kind::kTypedDataBase_length);
|
||||
}
|
||||
switch (array_cid) {
|
||||
|
||||
@@ -152,6 +152,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalGetSet) {
|
||||
kMatchAndMoveLoadIndexed,
|
||||
kMoveGlob,
|
||||
// Store 1
|
||||
kMatchAndMoveCheckWritable,
|
||||
kMoveParallelMoves,
|
||||
kMatchAndMoveLoadUntagged,
|
||||
kMoveParallelMoves,
|
||||
@@ -195,6 +196,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalGetSet) {
|
||||
kMatchAndMoveLoadIndexed,
|
||||
kMoveGlob,
|
||||
// Store 1
|
||||
kMatchAndMoveCheckWritable,
|
||||
kMoveParallelMoves,
|
||||
kMatchAndMoveLoadUntagged,
|
||||
kMoveParallelMoves,
|
||||
|
||||
@@ -1466,34 +1466,12 @@ void TypedDataSpecializer::EnsureIsInitialized() {
|
||||
td_class = typed_data.LookupClass(Symbols::iface()); \
|
||||
ASSERT(!td_class.IsNull()); \
|
||||
direct_implementors = td_class.direct_implementors(); \
|
||||
if (!HasThirdPartyImplementor(direct_implementors)) { \
|
||||
member_name = td_class.RareType(); \
|
||||
}
|
||||
member_name = td_class.RareType();
|
||||
|
||||
PUBLIC_TYPED_DATA_CLASS_LIST(INIT_HANDLE)
|
||||
#undef INIT_HANDLE
|
||||
}
|
||||
|
||||
bool TypedDataSpecializer::HasThirdPartyImplementor(
|
||||
const GrowableObjectArray& direct_implementors) {
|
||||
// Check if there are non internal/external/view implementors.
|
||||
for (intptr_t i = 0; i < direct_implementors.Length(); ++i) {
|
||||
implementor_ ^= direct_implementors.At(i);
|
||||
|
||||
// We only consider [implementor_] a 3rd party implementor if it was
|
||||
// finalized by the class finalizer, since only then can we have concrete
|
||||
// instances of the [implementor_].
|
||||
if (implementor_.is_finalized()) {
|
||||
const classid_t cid = implementor_.id();
|
||||
if (!IsTypedDataClassId(cid) && !IsTypedDataViewClassId(cid) &&
|
||||
!IsExternalTypedDataClassId(cid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TypedDataSpecializer::VisitInstanceCall(InstanceCallInstr* call) {
|
||||
TryInlineCall(call);
|
||||
}
|
||||
@@ -1609,6 +1587,7 @@ void TypedDataSpecializer::ReplaceWithIndexSet(TemplateDartCall<0>* call,
|
||||
if (value->Type()->is_nullable()) {
|
||||
AppendNullCheck(call, &value);
|
||||
}
|
||||
AppendMutableCheck(call, &array);
|
||||
AppendBoundsCheck(call, array, &index);
|
||||
AppendStoreIndexed(call, array, index, value, cid);
|
||||
|
||||
@@ -1627,6 +1606,16 @@ void TypedDataSpecializer::AppendNullCheck(TemplateDartCall<0>* call,
|
||||
*value = check;
|
||||
}
|
||||
|
||||
void TypedDataSpecializer::AppendMutableCheck(TemplateDartCall<0>* call,
|
||||
Definition** value) {
|
||||
auto check = new (Z) CheckWritableInstr(new (Z) Value(*value),
|
||||
call->deopt_id(), call->source());
|
||||
flow_graph_->InsertBefore(call, check, call->env(), FlowGraph::kValue);
|
||||
|
||||
// Use data dependency as control dependency.
|
||||
*value = check;
|
||||
}
|
||||
|
||||
void TypedDataSpecializer::AppendBoundsCheck(TemplateDartCall<0>* call,
|
||||
Definition* array,
|
||||
Definition** index) {
|
||||
|
||||
@@ -250,12 +250,12 @@ class TypedDataSpecializer : public FlowGraphVisitor {
|
||||
// clang-format on
|
||||
|
||||
void EnsureIsInitialized();
|
||||
bool HasThirdPartyImplementor(const GrowableObjectArray& direct_implementors);
|
||||
void TryInlineCall(TemplateDartCall<0>* call);
|
||||
void ReplaceWithLengthGetter(TemplateDartCall<0>* call);
|
||||
void ReplaceWithIndexGet(TemplateDartCall<0>* call, classid_t cid);
|
||||
void ReplaceWithIndexSet(TemplateDartCall<0>* call, classid_t cid);
|
||||
void AppendNullCheck(TemplateDartCall<0>* call, Definition** array);
|
||||
void AppendMutableCheck(TemplateDartCall<0>* call, Definition** array);
|
||||
void AppendBoundsCheck(TemplateDartCall<0>* call,
|
||||
Definition* array,
|
||||
Definition** index);
|
||||
|
||||
@@ -919,6 +919,21 @@ bool FlowGraphBuilder::IsRecognizedMethodForFlowGraph(
|
||||
case MethodRecognizer::kTypedData_Float32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_Int32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_Float64x2ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableByteDataView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt8ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint8ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint8ClampedArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt16ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint16ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableUint64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat32ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat64ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableInt32x4ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableFloat64x2ArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_Int8Array_factory:
|
||||
case MethodRecognizer::kTypedData_Uint8Array_factory:
|
||||
case MethodRecognizer::kTypedData_Uint8ClampedArray_factory:
|
||||
@@ -1065,122 +1080,27 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
|
||||
body += TailCall(resume_stub);
|
||||
break;
|
||||
}
|
||||
#define CASE(name) \
|
||||
case MethodRecognizer::kTypedData_##name##_factory: \
|
||||
body += BuildTypedDataFactoryConstructor(function, kTypedData##name##Cid); \
|
||||
break; \
|
||||
case MethodRecognizer::kTypedData_##name##View_factory: \
|
||||
body += BuildTypedDataViewFactoryConstructor(function, \
|
||||
kTypedData##name##ViewCid); \
|
||||
break; \
|
||||
case MethodRecognizer::kTypedData_Unmodifiable##name##View_factory: \
|
||||
body += BuildTypedDataViewFactoryConstructor( \
|
||||
function, kUnmodifiableTypedData##name##ViewCid); \
|
||||
break;
|
||||
CLASS_LIST_TYPED_DATA(CASE)
|
||||
#undef CASE
|
||||
case MethodRecognizer::kTypedData_ByteDataView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function, kByteDataViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int8ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function,
|
||||
kTypedDataInt8ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint8ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function,
|
||||
kTypedDataUint8ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint8ClampedArrayView_factory:
|
||||
case MethodRecognizer::kTypedData_UnmodifiableByteDataView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataUint8ClampedArrayViewCid);
|
||||
function, kUnmodifiableByteDataViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int16ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function,
|
||||
kTypedDataInt16ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint16ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataUint16ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int32ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function,
|
||||
kTypedDataInt32ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint32ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataUint32ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int64ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(function,
|
||||
kTypedDataInt64ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint64ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataUint64ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float32ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataFloat32ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float64ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataFloat64ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float32x4ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataFloat32x4ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int32x4ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataInt32x4ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float64x2ArrayView_factory:
|
||||
body += BuildTypedDataViewFactoryConstructor(
|
||||
function, kTypedDataFloat64x2ArrayViewCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int8Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataInt8ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint8Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataUint8ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint8ClampedArray_factory:
|
||||
body += BuildTypedDataFactoryConstructor(function,
|
||||
kTypedDataUint8ClampedArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int16Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataInt16ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint16Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataUint16ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int32Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataInt32ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint32Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataUint32ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int64Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataInt64ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Uint64Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataUint64ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float32Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataFloat32ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float64Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataFloat64ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float32x4Array_factory:
|
||||
body += BuildTypedDataFactoryConstructor(function,
|
||||
kTypedDataFloat32x4ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Int32x4Array_factory:
|
||||
body +=
|
||||
BuildTypedDataFactoryConstructor(function, kTypedDataInt32x4ArrayCid);
|
||||
break;
|
||||
case MethodRecognizer::kTypedData_Float64x2Array_factory:
|
||||
body += BuildTypedDataFactoryConstructor(function,
|
||||
kTypedDataFloat64x2ArrayCid);
|
||||
break;
|
||||
|
||||
case MethodRecognizer::kObjectEquals:
|
||||
ASSERT_EQUAL(function.NumParameters(), 2);
|
||||
body += LoadLocal(parsed_function_->RawParameterVariable(0));
|
||||
|
||||
@@ -65,6 +65,36 @@ namespace dart {
|
||||
V(_Float32x4ArrayView, ._, TypedData_Float32x4ArrayView_factory, 0x665eaec0) \
|
||||
V(_Int32x4ArrayView, ._, TypedData_Int32x4ArrayView_factory, 0x04b05d05) \
|
||||
V(_Float64x2ArrayView, ._, TypedData_Float64x2ArrayView_factory, 0x42e25ba4) \
|
||||
V(_UnmodifiableByteDataView, ._, \
|
||||
TypedData_UnmodifiableByteDataView_factory, 0x9afe180b) \
|
||||
V(_UnmodifiableInt8ArrayView, ._, \
|
||||
TypedData_UnmodifiableInt8ArrayView_factory, 0x4f2b458a) \
|
||||
V(_UnmodifiableUint8ArrayView, ._, \
|
||||
TypedData_UnmodifiableUint8ArrayView_factory, 0x44489049) \
|
||||
V(_UnmodifiableUint8ClampedArrayView, ._, \
|
||||
TypedData_UnmodifiableUint8ClampedArrayView_factory, 0x6a58f10d) \
|
||||
V(_UnmodifiableInt16ArrayView, ._, \
|
||||
TypedData_UnmodifiableInt16ArrayView_factory, 0xb6e82d3a) \
|
||||
V(_UnmodifiableUint16ArrayView, ._, \
|
||||
TypedData_UnmodifiableUint16ArrayView_factory, 0xa6dbb7d6) \
|
||||
V(_UnmodifiableInt32ArrayView, ._, \
|
||||
TypedData_UnmodifiableInt32ArrayView_factory, 0x48fd7ae4) \
|
||||
V(_UnmodifiableUint32ArrayView, ._, \
|
||||
TypedData_UnmodifiableUint32ArrayView_factory, 0x9525b674) \
|
||||
V(_UnmodifiableInt64ArrayView, ._, \
|
||||
TypedData_UnmodifiableInt64ArrayView_factory, 0x7652d544) \
|
||||
V(_UnmodifiableUint64ArrayView, ._, \
|
||||
TypedData_UnmodifiableUint64ArrayView_factory, 0x401bcd82) \
|
||||
V(_UnmodifiableFloat32ArrayView, ._, \
|
||||
TypedData_UnmodifiableFloat32ArrayView_factory, 0x54240389) \
|
||||
V(_UnmodifiableFloat64ArrayView, ._, \
|
||||
TypedData_UnmodifiableFloat64ArrayView_factory, 0xbf89ec6b) \
|
||||
V(_UnmodifiableFloat32x4ArrayView, ._, \
|
||||
TypedData_UnmodifiableFloat32x4ArrayView_factory, 0x5f25ea9a) \
|
||||
V(_UnmodifiableInt32x4ArrayView, ._, \
|
||||
TypedData_UnmodifiableInt32x4ArrayView_factory, 0xf67af1b2) \
|
||||
V(_UnmodifiableFloat64x2ArrayView, ._, \
|
||||
TypedData_UnmodifiableFloat64x2ArrayView_factory, 0x6da96e1a) \
|
||||
V(Int8List, ., TypedData_Int8Array_factory, 0x660dd888) \
|
||||
V(Uint8List, ., TypedData_Uint8Array_factory, 0xede3f64f) \
|
||||
V(Uint8ClampedList, ., TypedData_Uint8ClampedArray_factory, 0x28063755) \
|
||||
|
||||
@@ -345,7 +345,9 @@ uword MakeTagWordForNewSpaceObject(classid_t cid, uword instance_size) {
|
||||
return dart::UntaggedObject::SizeTag::encode(
|
||||
TranslateOffsetInWordsToHost(instance_size)) |
|
||||
dart::UntaggedObject::ClassIdTag::encode(cid) |
|
||||
dart::UntaggedObject::NewBit::encode(true);
|
||||
dart::UntaggedObject::NewBit::encode(true) |
|
||||
dart::UntaggedObject::ImmutableBit::encode(
|
||||
IsUnmodifiableTypedDataViewClassId(cid));
|
||||
}
|
||||
|
||||
word Object::tags_offset() {
|
||||
@@ -363,6 +365,8 @@ const word UntaggedObject::kOldAndNotRememberedBit =
|
||||
const word UntaggedObject::kOldAndNotMarkedBit =
|
||||
dart::UntaggedObject::kOldAndNotMarkedBit;
|
||||
|
||||
const word UntaggedObject::kImmutableBit = dart::UntaggedObject::kImmutableBit;
|
||||
|
||||
const word UntaggedObject::kSizeTagPos = dart::UntaggedObject::kSizeTagPos;
|
||||
|
||||
const word UntaggedObject::kSizeTagSize = dart::UntaggedObject::kSizeTagSize;
|
||||
@@ -457,6 +461,7 @@ static uword GetInstanceSizeImpl(const dart::Class& handle) {
|
||||
return NativeFinalizer::InstanceSize();
|
||||
case kByteBufferCid:
|
||||
case kByteDataViewCid:
|
||||
case kUnmodifiableByteDataViewCid:
|
||||
case kPointerCid:
|
||||
case kDynamicLibraryCid:
|
||||
#define HANDLE_CASE(clazz) case kFfi##clazz##Cid:
|
||||
@@ -465,7 +470,8 @@ static uword GetInstanceSizeImpl(const dart::Class& handle) {
|
||||
#define HANDLE_CASE(clazz) \
|
||||
case kTypedData##clazz##Cid: \
|
||||
case kTypedData##clazz##ViewCid: \
|
||||
case kExternalTypedData##clazz##Cid:
|
||||
case kExternalTypedData##clazz##Cid: \
|
||||
case kUnmodifiableTypedData##clazz##ViewCid:
|
||||
CLASS_LIST_TYPED_DATA(HANDLE_CASE)
|
||||
#undef HANDLE_CASE
|
||||
return handle.target_instance_size();
|
||||
@@ -547,7 +553,8 @@ word Instance::DataOffsetFor(intptr_t cid) {
|
||||
|
||||
word Instance::ElementSizeFor(intptr_t cid) {
|
||||
if (dart::IsExternalTypedDataClassId(cid) || dart::IsTypedDataClassId(cid) ||
|
||||
dart::IsTypedDataViewClassId(cid)) {
|
||||
dart::IsTypedDataViewClassId(cid) ||
|
||||
dart::IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
return dart::TypedDataBase::ElementSizeInBytes(cid);
|
||||
}
|
||||
switch (cid) {
|
||||
|
||||
@@ -413,6 +413,7 @@ class UntaggedObject : public AllStatic {
|
||||
static const word kCanonicalBit;
|
||||
static const word kOldAndNotRememberedBit;
|
||||
static const word kOldAndNotMarkedBit;
|
||||
static const word kImmutableBit;
|
||||
static const word kSizeTagPos;
|
||||
static const word kSizeTagSize;
|
||||
static const word kClassIdTagPos;
|
||||
@@ -1208,6 +1209,8 @@ class Thread : public AllStatic {
|
||||
static word null_cast_error_shared_with_fpu_regs_stub_offset();
|
||||
static word range_error_shared_without_fpu_regs_stub_offset();
|
||||
static word range_error_shared_with_fpu_regs_stub_offset();
|
||||
static word write_error_shared_without_fpu_regs_stub_offset();
|
||||
static word write_error_shared_with_fpu_regs_stub_offset();
|
||||
static word resume_stub_offset();
|
||||
static word return_async_not_future_stub_offset();
|
||||
static word return_async_star_stub_offset();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -276,6 +276,8 @@
|
||||
FIELD(Thread, null_cast_error_shared_without_fpu_regs_stub_offset) \
|
||||
FIELD(Thread, range_error_shared_with_fpu_regs_stub_offset) \
|
||||
FIELD(Thread, range_error_shared_without_fpu_regs_stub_offset) \
|
||||
FIELD(Thread, write_error_shared_with_fpu_regs_stub_offset) \
|
||||
FIELD(Thread, write_error_shared_without_fpu_regs_stub_offset) \
|
||||
FIELD(Thread, resume_stub_offset) \
|
||||
FIELD(Thread, return_async_not_future_stub_offset) \
|
||||
FIELD(Thread, return_async_star_stub_offset) \
|
||||
|
||||
@@ -1186,6 +1186,16 @@ void StubCodeCompiler::GenerateRangeErrorSharedWithFPURegsStub(
|
||||
GenerateRangeError(assembler, /*with_fpu_regs=*/true);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteErrorSharedWithoutFPURegsStub(
|
||||
Assembler* assembler) {
|
||||
GenerateWriteError(assembler, /*with_fpu_regs=*/false);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteErrorSharedWithFPURegsStub(
|
||||
Assembler* assembler) {
|
||||
GenerateWriteError(assembler, /*with_fpu_regs=*/true);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateFrameAwaitingMaterializationStub(
|
||||
Assembler* assembler) {
|
||||
__ Breakpoint(); // Marker stub.
|
||||
|
||||
@@ -198,6 +198,7 @@ class StubCodeCompiler : public AllStatic {
|
||||
bool with_fpu_regs);
|
||||
|
||||
static void GenerateRangeError(Assembler* assembler, bool with_fpu_regs);
|
||||
static void GenerateWriteError(Assembler* assembler, bool with_fpu_regs);
|
||||
|
||||
static void GenerateSuspendStub(
|
||||
Assembler* assembler,
|
||||
|
||||
@@ -521,6 +521,21 @@ void StubCodeCompiler::GenerateRangeError(Assembler* assembler,
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteError(Assembler* assembler,
|
||||
bool with_fpu_regs) {
|
||||
auto perform_runtime_call = [&]() {
|
||||
__ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
|
||||
__ Breakpoint();
|
||||
};
|
||||
|
||||
GenerateSharedStubGeneric(
|
||||
assembler, /*save_fpu_registers=*/with_fpu_regs,
|
||||
with_fpu_regs
|
||||
? target::Thread::write_error_shared_with_fpu_regs_stub_offset()
|
||||
: target::Thread::write_error_shared_without_fpu_regs_stub_offset(),
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
// Input parameters:
|
||||
// LR : return address.
|
||||
// SP : address of return value.
|
||||
|
||||
@@ -737,6 +737,21 @@ void StubCodeCompiler::GenerateRangeError(Assembler* assembler,
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteError(Assembler* assembler,
|
||||
bool with_fpu_regs) {
|
||||
auto perform_runtime_call = [&]() {
|
||||
__ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
|
||||
__ Breakpoint();
|
||||
};
|
||||
|
||||
GenerateSharedStubGeneric(
|
||||
assembler, /*save_fpu_registers=*/with_fpu_regs,
|
||||
with_fpu_regs
|
||||
? target::Thread::write_error_shared_with_fpu_regs_stub_offset()
|
||||
: target::Thread::write_error_shared_without_fpu_regs_stub_offset(),
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
// Input parameters:
|
||||
// LR : return address.
|
||||
// SP : address of return value.
|
||||
|
||||
@@ -372,6 +372,12 @@ void StubCodeCompiler::GenerateRangeError(Assembler* assembler,
|
||||
__ Breakpoint();
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteError(Assembler* assembler,
|
||||
bool with_fpu_regs) {
|
||||
// Only used in AOT.
|
||||
__ Breakpoint();
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateDispatchTableNullErrorStub(
|
||||
Assembler* assembler) {
|
||||
// Only used in AOT.
|
||||
|
||||
@@ -576,6 +576,21 @@ void StubCodeCompiler::GenerateRangeError(Assembler* assembler,
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteError(Assembler* assembler,
|
||||
bool with_fpu_regs) {
|
||||
auto perform_runtime_call = [&]() {
|
||||
__ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
|
||||
__ Breakpoint();
|
||||
};
|
||||
|
||||
GenerateSharedStubGeneric(
|
||||
assembler, /*save_fpu_registers=*/with_fpu_regs,
|
||||
with_fpu_regs
|
||||
? target::Thread::write_error_shared_with_fpu_regs_stub_offset()
|
||||
: target::Thread::write_error_shared_without_fpu_regs_stub_offset(),
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
// Input parameters:
|
||||
// RA : return address.
|
||||
// SP : address of return value.
|
||||
|
||||
@@ -671,6 +671,21 @@ void StubCodeCompiler::GenerateRangeError(Assembler* assembler,
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
void StubCodeCompiler::GenerateWriteError(Assembler* assembler,
|
||||
bool with_fpu_regs) {
|
||||
auto perform_runtime_call = [&]() {
|
||||
__ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
|
||||
__ Breakpoint();
|
||||
};
|
||||
|
||||
GenerateSharedStubGeneric(
|
||||
assembler, /*save_fpu_registers=*/with_fpu_regs,
|
||||
with_fpu_regs
|
||||
? target::Thread::write_error_shared_with_fpu_regs_stub_offset()
|
||||
: target::Thread::write_error_shared_without_fpu_regs_stub_offset(),
|
||||
/*allow_return=*/false, perform_runtime_call);
|
||||
}
|
||||
|
||||
// Input parameters:
|
||||
// RSP : points to return address.
|
||||
// RSP + 8 : address of return value.
|
||||
|
||||
@@ -2468,7 +2468,7 @@ DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) {
|
||||
TransitionNativeToVM transition(thread);
|
||||
intptr_t cid = Api::ClassId(handle);
|
||||
return IsTypedDataClassId(cid) || IsExternalTypedDataClassId(cid) ||
|
||||
IsTypedDataViewClassId(cid);
|
||||
IsTypedDataViewClassId(cid) || IsUnmodifiableTypedDataViewClassId(cid);
|
||||
}
|
||||
|
||||
DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) {
|
||||
@@ -3655,75 +3655,90 @@ static Dart_TypedData_Type GetType(intptr_t class_id) {
|
||||
Dart_TypedData_Type type;
|
||||
switch (class_id) {
|
||||
case kByteDataViewCid:
|
||||
case kUnmodifiableByteDataViewCid:
|
||||
type = Dart_TypedData_kByteData;
|
||||
break;
|
||||
case kTypedDataInt8ArrayCid:
|
||||
case kTypedDataInt8ArrayViewCid:
|
||||
case kUnmodifiableTypedDataInt8ArrayViewCid:
|
||||
case kExternalTypedDataInt8ArrayCid:
|
||||
type = Dart_TypedData_kInt8;
|
||||
break;
|
||||
case kTypedDataUint8ArrayCid:
|
||||
case kTypedDataUint8ArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint8ArrayViewCid:
|
||||
case kExternalTypedDataUint8ArrayCid:
|
||||
type = Dart_TypedData_kUint8;
|
||||
break;
|
||||
case kTypedDataUint8ClampedArrayCid:
|
||||
case kTypedDataUint8ClampedArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
|
||||
case kExternalTypedDataUint8ClampedArrayCid:
|
||||
type = Dart_TypedData_kUint8Clamped;
|
||||
break;
|
||||
case kTypedDataInt16ArrayCid:
|
||||
case kTypedDataInt16ArrayViewCid:
|
||||
case kUnmodifiableTypedDataInt16ArrayViewCid:
|
||||
case kExternalTypedDataInt16ArrayCid:
|
||||
type = Dart_TypedData_kInt16;
|
||||
break;
|
||||
case kTypedDataUint16ArrayCid:
|
||||
case kTypedDataUint16ArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint16ArrayViewCid:
|
||||
case kExternalTypedDataUint16ArrayCid:
|
||||
type = Dart_TypedData_kUint16;
|
||||
break;
|
||||
case kTypedDataInt32ArrayCid:
|
||||
case kTypedDataInt32ArrayViewCid:
|
||||
case kUnmodifiableTypedDataInt32ArrayViewCid:
|
||||
case kExternalTypedDataInt32ArrayCid:
|
||||
type = Dart_TypedData_kInt32;
|
||||
break;
|
||||
case kTypedDataUint32ArrayCid:
|
||||
case kTypedDataUint32ArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint32ArrayViewCid:
|
||||
case kExternalTypedDataUint32ArrayCid:
|
||||
type = Dart_TypedData_kUint32;
|
||||
break;
|
||||
case kTypedDataInt64ArrayCid:
|
||||
case kTypedDataInt64ArrayViewCid:
|
||||
case kUnmodifiableTypedDataInt64ArrayViewCid:
|
||||
case kExternalTypedDataInt64ArrayCid:
|
||||
type = Dart_TypedData_kInt64;
|
||||
break;
|
||||
case kTypedDataUint64ArrayCid:
|
||||
case kTypedDataUint64ArrayViewCid:
|
||||
case kUnmodifiableTypedDataUint64ArrayViewCid:
|
||||
case kExternalTypedDataUint64ArrayCid:
|
||||
type = Dart_TypedData_kUint64;
|
||||
break;
|
||||
case kTypedDataFloat32ArrayCid:
|
||||
case kTypedDataFloat32ArrayViewCid:
|
||||
case kUnmodifiableTypedDataFloat32ArrayViewCid:
|
||||
case kExternalTypedDataFloat32ArrayCid:
|
||||
type = Dart_TypedData_kFloat32;
|
||||
break;
|
||||
case kTypedDataFloat64ArrayCid:
|
||||
case kTypedDataFloat64ArrayViewCid:
|
||||
case kUnmodifiableTypedDataFloat64ArrayViewCid:
|
||||
case kExternalTypedDataFloat64ArrayCid:
|
||||
type = Dart_TypedData_kFloat64;
|
||||
break;
|
||||
case kTypedDataInt32x4ArrayCid:
|
||||
case kTypedDataInt32x4ArrayViewCid:
|
||||
case kUnmodifiableTypedDataInt32x4ArrayViewCid:
|
||||
case kExternalTypedDataInt32x4ArrayCid:
|
||||
type = Dart_TypedData_kInt32x4;
|
||||
break;
|
||||
case kTypedDataFloat32x4ArrayCid:
|
||||
case kTypedDataFloat32x4ArrayViewCid:
|
||||
case kUnmodifiableTypedDataFloat32x4ArrayViewCid:
|
||||
case kExternalTypedDataFloat32x4ArrayCid:
|
||||
type = Dart_TypedData_kFloat32x4;
|
||||
break;
|
||||
case kTypedDataFloat64x2ArrayCid:
|
||||
case kTypedDataFloat64x2ArrayViewCid:
|
||||
case kUnmodifiableTypedDataFloat64x2ArrayViewCid:
|
||||
case kExternalTypedDataFloat64x2ArrayCid:
|
||||
type = Dart_TypedData_kFloat64x2;
|
||||
break;
|
||||
@@ -3739,7 +3754,8 @@ DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) {
|
||||
API_TIMELINE_DURATION(thread);
|
||||
TransitionNativeToVM transition(thread);
|
||||
intptr_t class_id = Api::ClassId(object);
|
||||
if (IsTypedDataClassId(class_id) || IsTypedDataViewClassId(class_id)) {
|
||||
if (IsTypedDataClassId(class_id) || IsTypedDataViewClassId(class_id) ||
|
||||
IsUnmodifiableTypedDataViewClassId(class_id)) {
|
||||
return GetType(class_id);
|
||||
}
|
||||
return Dart_TypedData_kInvalid;
|
||||
@@ -3754,7 +3770,8 @@ Dart_GetTypeOfExternalTypedData(Dart_Handle object) {
|
||||
if (IsExternalTypedDataClassId(class_id)) {
|
||||
return GetType(class_id);
|
||||
}
|
||||
if (IsTypedDataViewClassId(class_id)) {
|
||||
if (IsTypedDataViewClassId(class_id) ||
|
||||
IsUnmodifiableTypedDataViewClassId(class_id)) {
|
||||
// Check if data object of the view is external.
|
||||
Zone* zone = thread->zone();
|
||||
const auto& view_obj = Api::UnwrapTypedDataViewHandle(zone, object);
|
||||
@@ -4086,7 +4103,8 @@ DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object,
|
||||
Isolate* I = T->isolate();
|
||||
intptr_t class_id = Api::ClassId(object);
|
||||
if (!IsExternalTypedDataClassId(class_id) &&
|
||||
!IsTypedDataViewClassId(class_id) && !IsTypedDataClassId(class_id)) {
|
||||
!IsTypedDataViewClassId(class_id) && !IsTypedDataClassId(class_id) &&
|
||||
!IsUnmodifiableTypedDataViewClassId(class_id)) {
|
||||
RETURN_TYPE_ERROR(Z, object, 'TypedData');
|
||||
}
|
||||
if (type == NULL) {
|
||||
@@ -4121,7 +4139,8 @@ DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object,
|
||||
size_in_bytes = length * TypedData::ElementSizeInBytes(class_id);
|
||||
data_tmp = obj.DataAddr(0);
|
||||
} else {
|
||||
ASSERT(IsTypedDataViewClassId(class_id));
|
||||
ASSERT(IsTypedDataViewClassId(class_id) ||
|
||||
IsUnmodifiableTypedDataViewClassId(class_id));
|
||||
const auto& view_obj = Api::UnwrapTypedDataViewHandle(Z, object);
|
||||
ASSERT(!view_obj.IsNull());
|
||||
Smi& val = Smi::Handle();
|
||||
@@ -4182,7 +4201,8 @@ DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) {
|
||||
Isolate* I = T->isolate();
|
||||
intptr_t class_id = Api::ClassId(object);
|
||||
if (!IsExternalTypedDataClassId(class_id) &&
|
||||
!IsTypedDataViewClassId(class_id) && !IsTypedDataClassId(class_id)) {
|
||||
!IsTypedDataViewClassId(class_id) && !IsTypedDataClassId(class_id) &&
|
||||
!IsUnmodifiableTypedDataViewClassId(class_id)) {
|
||||
RETURN_TYPE_ERROR(Z, object, 'TypedData');
|
||||
}
|
||||
if (FLAG_verify_acquired_data) {
|
||||
|
||||
@@ -2139,6 +2139,30 @@ TEST_CASE(DartAPI_TypedDataViewListIsTypedData) {
|
||||
EXPECT_VALID(view_obj);
|
||||
// Test that the API considers it a TypedData object.
|
||||
EXPECT(Dart_IsTypedData(view_obj));
|
||||
EXPECT_EQ(Dart_TypedData_kInt8, Dart_GetTypeOfTypedData(view_obj));
|
||||
}
|
||||
|
||||
TEST_CASE(DartAPI_UnmodifiableTypedDataViewListIsTypedData) {
|
||||
const int kSize = 1000;
|
||||
|
||||
const char* kScriptChars =
|
||||
"import 'dart:typed_data';\n"
|
||||
"List testMain(int size) {\n"
|
||||
" var a = new Int8List(size);\n"
|
||||
" var view = new UnmodifiableInt8ListView(a);\n"
|
||||
" return view;\n"
|
||||
"}\n";
|
||||
// Create a test library and Load up a test script in it.
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
|
||||
// Create a typed data view object.
|
||||
Dart_Handle dart_args[1];
|
||||
dart_args[0] = Dart_NewInteger(kSize);
|
||||
Dart_Handle view_obj = Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
|
||||
EXPECT_VALID(view_obj);
|
||||
// Test that the API considers it a TypedData object.
|
||||
EXPECT(Dart_IsTypedData(view_obj));
|
||||
EXPECT_EQ(Dart_TypedData_kInt8, Dart_GetTypeOfTypedData(view_obj));
|
||||
}
|
||||
|
||||
TEST_CASE(DartAPI_TypedDataAccess) {
|
||||
@@ -2760,6 +2784,59 @@ TEST_CASE(DartAPI_TypedDataViewDirectAccessVerified) {
|
||||
TestTypedDataViewDirectAccess();
|
||||
}
|
||||
|
||||
static void TestUnmodifiableTypedDataViewDirectAccess() {
|
||||
const char* kScriptChars =
|
||||
"import 'dart:typed_data';\n"
|
||||
"List main() {"
|
||||
" var list = new Int8List(100);"
|
||||
" for (var i = 0; i < 100; i++) {"
|
||||
" list[i] = i;"
|
||||
" }"
|
||||
" return new UnmodifiableInt8ListView(list);"
|
||||
"}\n";
|
||||
// Create a test library and Load up a test script in it.
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
|
||||
// Test with a typed data view object.
|
||||
Dart_Handle view_obj;
|
||||
view_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
EXPECT_VALID(view_obj);
|
||||
|
||||
const int kLength = 100;
|
||||
Dart_TypedData_Type type;
|
||||
void* data;
|
||||
intptr_t len;
|
||||
Dart_Handle result = Dart_TypedDataAcquireData(view_obj, &type, &data, &len);
|
||||
EXPECT(!Thread::Current()->IsAtSafepoint());
|
||||
EXPECT_VALID(result);
|
||||
EXPECT_EQ(Dart_TypedData_kInt8, type);
|
||||
EXPECT_EQ(kLength, len);
|
||||
int8_t* dataP = reinterpret_cast<int8_t*>(data);
|
||||
for (int i = 0; i < kLength; i++) {
|
||||
EXPECT_EQ(i, dataP[i]);
|
||||
}
|
||||
|
||||
// Now try allocating a string with outstanding Acquires and it should
|
||||
// return an error.
|
||||
result = NewString("We expect an error here");
|
||||
EXPECT_ERROR(result, "Callbacks into the Dart VM are currently prohibited");
|
||||
|
||||
// Release direct access to the typed data object.
|
||||
EXPECT(!Thread::Current()->IsAtSafepoint());
|
||||
result = Dart_TypedDataReleaseData(view_obj);
|
||||
EXPECT_VALID(result);
|
||||
}
|
||||
|
||||
TEST_CASE(DartAPI_UnmodifiableTypedDataViewDirectAccessUnverified) {
|
||||
FLAG_verify_acquired_data = false;
|
||||
TestUnmodifiableTypedDataViewDirectAccess();
|
||||
}
|
||||
|
||||
TEST_CASE(DartAPI_UnmodifiableTypedDataViewDirectAccessVerified) {
|
||||
FLAG_verify_acquired_data = true;
|
||||
TestUnmodifiableTypedDataViewDirectAccess();
|
||||
}
|
||||
|
||||
static void TestByteDataDirectAccess() {
|
||||
const char* kScriptChars =
|
||||
"import 'dart:typed_data';\n"
|
||||
|
||||
@@ -180,7 +180,8 @@ class ScavengerVisitorBase : public ObjectPointerVisitor {
|
||||
// Validate 'this' is a typed data view.
|
||||
const uword view_header = ReadHeaderRelaxed(view);
|
||||
ASSERT(!IsForwarding(view_header) || view->IsOldObject());
|
||||
ASSERT(IsTypedDataViewClassId(view->GetClassIdMayBeSmi()));
|
||||
ASSERT(IsTypedDataViewClassId(view->GetClassIdMayBeSmi()) ||
|
||||
IsUnmodifiableTypedDataViewClassId(view->GetClassIdMayBeSmi()));
|
||||
|
||||
// Validate that the backing store is not a forwarding word. There is a data
|
||||
// race reader the backing store's header unless there is only one worker.
|
||||
|
||||
@@ -3463,7 +3463,9 @@ MessageSerializationCluster* BaseSerializer::NewClusterForClass(
|
||||
(cid == kByteBufferCid)) {
|
||||
return new (Z) InstanceMessageSerializationCluster(is_canonical, cid);
|
||||
}
|
||||
if (IsTypedDataViewClassId(cid) || cid == kByteDataViewCid) {
|
||||
if (IsTypedDataViewClassId(cid) || cid == kByteDataViewCid ||
|
||||
IsUnmodifiableTypedDataViewClassId(cid) ||
|
||||
cid == kUnmodifiableByteDataViewCid) {
|
||||
return new (Z) TypedDataViewMessageSerializationCluster(Z, cid);
|
||||
}
|
||||
if (IsExternalTypedDataClassId(cid)) {
|
||||
@@ -3552,7 +3554,9 @@ MessageDeserializationCluster* BaseDeserializer::ReadCluster() {
|
||||
(cid == kByteBufferCid)) {
|
||||
return new (Z) InstanceMessageDeserializationCluster(is_canonical);
|
||||
}
|
||||
if (IsTypedDataViewClassId(cid) || cid == kByteDataViewCid) {
|
||||
if (IsTypedDataViewClassId(cid) || cid == kByteDataViewCid ||
|
||||
IsUnmodifiableTypedDataViewClassId(cid) ||
|
||||
cid == kUnmodifiableByteDataViewCid) {
|
||||
ASSERT(!is_canonical);
|
||||
return new (Z) TypedDataViewMessageDeserializationCluster(cid);
|
||||
}
|
||||
|
||||
+47
-14
@@ -684,6 +684,8 @@ void Object::InitVtables() {
|
||||
builtin_vtables_[kTypedData##clazz##Cid] = fake_internal_handle.vtable(); \
|
||||
TypedDataView fake_view_handle; \
|
||||
builtin_vtables_[kTypedData##clazz##ViewCid] = fake_view_handle.vtable(); \
|
||||
builtin_vtables_[kUnmodifiableTypedData##clazz##ViewCid] = \
|
||||
fake_view_handle.vtable(); \
|
||||
ExternalTypedData fake_external_handle; \
|
||||
builtin_vtables_[kExternalTypedData##clazz##Cid] = \
|
||||
fake_external_handle.vtable(); \
|
||||
@@ -694,6 +696,7 @@ void Object::InitVtables() {
|
||||
{
|
||||
TypedDataView fake_handle;
|
||||
builtin_vtables_[kByteDataViewCid] = fake_handle.vtable();
|
||||
builtin_vtables_[kUnmodifiableByteDataViewCid] = fake_handle.vtable();
|
||||
}
|
||||
|
||||
{
|
||||
@@ -2112,6 +2115,10 @@ ErrorPtr Object::Init(IsolateGroup* isolate_group,
|
||||
cls = \
|
||||
Class::NewTypedDataViewClass(kTypedData##clazz##ViewCid, isolate_group); \
|
||||
RegisterPrivateClass(cls, Symbols::_##clazz##View(), lib); \
|
||||
pending_classes.Add(cls); \
|
||||
cls = Class::NewUnmodifiableTypedDataViewClass( \
|
||||
kUnmodifiableTypedData##clazz##ViewCid, isolate_group); \
|
||||
RegisterPrivateClass(cls, Symbols::_Unmodifiable##clazz##View(), lib); \
|
||||
pending_classes.Add(cls);
|
||||
|
||||
CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_VIEW_CLASS);
|
||||
@@ -2119,6 +2126,10 @@ ErrorPtr Object::Init(IsolateGroup* isolate_group,
|
||||
cls = Class::NewTypedDataViewClass(kByteDataViewCid, isolate_group);
|
||||
RegisterPrivateClass(cls, Symbols::_ByteDataView(), lib);
|
||||
pending_classes.Add(cls);
|
||||
cls = Class::NewUnmodifiableTypedDataViewClass(kUnmodifiableByteDataViewCid,
|
||||
isolate_group);
|
||||
RegisterPrivateClass(cls, Symbols::_UnmodifiableByteDataView(), lib);
|
||||
pending_classes.Add(cls);
|
||||
|
||||
#undef REGISTER_TYPED_DATA_VIEW_CLASS
|
||||
#define REGISTER_EXT_TYPED_DATA_CLASS(clazz) \
|
||||
@@ -2502,10 +2513,15 @@ ErrorPtr Object::Init(IsolateGroup* isolate_group,
|
||||
CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS);
|
||||
#undef REGISTER_TYPED_DATA_CLASS
|
||||
#define REGISTER_TYPED_DATA_VIEW_CLASS(clazz) \
|
||||
cls = Class::NewTypedDataViewClass(kTypedData##clazz##ViewCid, isolate_group);
|
||||
cls = \
|
||||
Class::NewTypedDataViewClass(kTypedData##clazz##ViewCid, isolate_group); \
|
||||
cls = Class::NewUnmodifiableTypedDataViewClass( \
|
||||
kUnmodifiableTypedData##clazz##ViewCid, isolate_group);
|
||||
CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_VIEW_CLASS);
|
||||
#undef REGISTER_TYPED_DATA_VIEW_CLASS
|
||||
cls = Class::NewTypedDataViewClass(kByteDataViewCid, isolate_group);
|
||||
cls = Class::NewUnmodifiableTypedDataViewClass(kUnmodifiableByteDataViewCid,
|
||||
isolate_group);
|
||||
#define REGISTER_EXT_TYPED_DATA_CLASS(clazz) \
|
||||
cls = Class::NewExternalTypedDataClass(kExternalTypedData##clazz##Cid, \
|
||||
isolate_group);
|
||||
@@ -2877,6 +2893,7 @@ bool Class::HasCompressedPointers() const {
|
||||
case kTypedData##clazz##Cid: \
|
||||
return dart::TypedData::ContainsCompressedPointers(); \
|
||||
case kTypedData##clazz##ViewCid: \
|
||||
case kUnmodifiableTypedData##clazz##ViewCid: \
|
||||
return dart::TypedDataView::ContainsCompressedPointers(); \
|
||||
case kExternalTypedData##clazz##Cid: \
|
||||
return dart::ExternalTypedData::ContainsCompressedPointers();
|
||||
@@ -4915,6 +4932,26 @@ ClassPtr Class::NewTypedDataViewClass(intptr_t class_id,
|
||||
return result.ptr();
|
||||
}
|
||||
|
||||
ClassPtr Class::NewUnmodifiableTypedDataViewClass(intptr_t class_id,
|
||||
IsolateGroup* isolate_group) {
|
||||
ASSERT(IsUnmodifiableTypedDataViewClassId(class_id));
|
||||
const intptr_t host_instance_size = TypedDataView::InstanceSize();
|
||||
const intptr_t target_instance_size = compiler::target::RoundedAllocationSize(
|
||||
RTN::TypedDataView::InstanceSize());
|
||||
Class& result = Class::Handle(New<TypedDataView, RTN::TypedDataView>(
|
||||
class_id, isolate_group, /*register_class=*/false));
|
||||
result.set_instance_size(host_instance_size, target_instance_size);
|
||||
|
||||
const intptr_t host_next_field_offset = TypedDataView::NextFieldOffset();
|
||||
const intptr_t target_next_field_offset =
|
||||
RTN::TypedDataView::NextFieldOffset();
|
||||
result.set_next_field_offset(host_next_field_offset,
|
||||
target_next_field_offset);
|
||||
result.set_is_prefinalized();
|
||||
isolate_group->class_table()->Register(result);
|
||||
return result.ptr();
|
||||
}
|
||||
|
||||
ClassPtr Class::NewExternalTypedDataClass(intptr_t class_id,
|
||||
IsolateGroup* isolate_group) {
|
||||
ASSERT(IsExternalTypedDataClassId(class_id));
|
||||
@@ -8146,7 +8183,7 @@ void Function::SetIsOptimizable(bool value) const {
|
||||
|
||||
bool Function::ForceOptimize() const {
|
||||
return RecognizedKindForceOptimize() || IsFfiTrampoline() ||
|
||||
IsTypedDataViewFactory();
|
||||
IsTypedDataViewFactory() || IsUnmodifiableTypedDataViewFactory();
|
||||
}
|
||||
|
||||
bool Function::RecognizedKindForceOptimize() const {
|
||||
@@ -11324,6 +11361,7 @@ static intptr_t GetListLength(const Object& value) {
|
||||
|
||||
static intptr_t GetListLengthOffset(intptr_t cid) {
|
||||
if (IsTypedDataClassId(cid) || IsTypedDataViewClassId(cid) ||
|
||||
IsUnmodifiableTypedDataViewClassId(cid) ||
|
||||
IsExternalTypedDataClassId(cid)) {
|
||||
return TypedData::length_offset();
|
||||
} else if (cid == kArrayCid || cid == kImmutableArrayCid) {
|
||||
@@ -19921,7 +19959,7 @@ bool Instance::IsValidFieldOffset(intptr_t offset) const {
|
||||
|
||||
intptr_t Instance::ElementSizeFor(intptr_t cid) {
|
||||
if (IsExternalTypedDataClassId(cid) || IsTypedDataClassId(cid) ||
|
||||
IsTypedDataViewClassId(cid)) {
|
||||
IsTypedDataViewClassId(cid) || IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
return TypedDataBase::ElementSizeInBytes(cid);
|
||||
}
|
||||
switch (cid) {
|
||||
@@ -25309,14 +25347,8 @@ TypedDataPtr TypedData::New(intptr_t class_id,
|
||||
}
|
||||
|
||||
const char* TypedData::ToCString() const {
|
||||
switch (GetClassId()) {
|
||||
#define CASE_TYPED_DATA_CLASS(clazz) \
|
||||
case kTypedData##clazz##Cid: \
|
||||
return #clazz;
|
||||
CLASS_LIST_TYPED_DATA(CASE_TYPED_DATA_CLASS);
|
||||
#undef CASE_TYPED_DATA_CLASS
|
||||
}
|
||||
return "TypedData";
|
||||
const Class& cls = Class::Handle(clazz());
|
||||
return cls.ScrubbedNameCString();
|
||||
}
|
||||
|
||||
FinalizablePersistentHandle* ExternalTypedData::AddFinalizer(
|
||||
@@ -25394,12 +25426,13 @@ const char* TypedDataBase::ToCString() const {
|
||||
}
|
||||
|
||||
const char* TypedDataView::ToCString() const {
|
||||
auto zone = Thread::Current()->zone();
|
||||
return OS::SCreate(zone, "TypedDataView(cid: %" Pd ")", GetClassId());
|
||||
const Class& cls = Class::Handle(clazz());
|
||||
return cls.ScrubbedNameCString();
|
||||
}
|
||||
|
||||
const char* ExternalTypedData::ToCString() const {
|
||||
return "ExternalTypedData";
|
||||
const Class& cls = Class::Handle(clazz());
|
||||
return cls.ScrubbedNameCString();
|
||||
}
|
||||
|
||||
PointerPtr Pointer::New(const AbstractType& type_arg,
|
||||
|
||||
+23
-6
@@ -1732,6 +1732,9 @@ class Class : public Object {
|
||||
// Allocate the raw TypedDataView/ByteDataView classes.
|
||||
static ClassPtr NewTypedDataViewClass(intptr_t class_id,
|
||||
IsolateGroup* isolate_group);
|
||||
static ClassPtr NewUnmodifiableTypedDataViewClass(
|
||||
intptr_t class_id,
|
||||
IsolateGroup* isolate_group);
|
||||
|
||||
// Allocate the raw ExternalTypedData classes.
|
||||
static ClassPtr NewExternalTypedDataClass(intptr_t class_id,
|
||||
@@ -3624,6 +3627,15 @@ class Function : public Object {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsUnmodifiableTypedDataViewFactory() const {
|
||||
if (is_native() && kind() == UntaggedFunction::kConstructor) {
|
||||
// This is a native factory constructor.
|
||||
const Class& klass = Class::Handle(Owner());
|
||||
return IsUnmodifiableTypedDataViewClassId(klass.id());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DART_WARN_UNUSED_RESULT
|
||||
ErrorPtr VerifyCallEntryPoint() const;
|
||||
|
||||
@@ -10723,20 +10735,25 @@ class TypedDataBase : public PointerBase {
|
||||
}
|
||||
|
||||
static TypedDataElementType ElementType(classid_t cid) {
|
||||
if (cid == kByteDataViewCid) {
|
||||
if (cid == kByteDataViewCid || cid == kUnmodifiableByteDataViewCid) {
|
||||
return kUint8ArrayElement;
|
||||
} else if (IsTypedDataClassId(cid)) {
|
||||
const intptr_t index =
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderInternal) / 3;
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderInternal) / 4;
|
||||
return static_cast<TypedDataElementType>(index);
|
||||
} else if (IsTypedDataViewClassId(cid)) {
|
||||
const intptr_t index =
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderView) / 3;
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderView) / 4;
|
||||
return static_cast<TypedDataElementType>(index);
|
||||
} else if (IsExternalTypedDataClassId(cid)) {
|
||||
const intptr_t index =
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderExternal) / 4;
|
||||
return static_cast<TypedDataElementType>(index);
|
||||
} else {
|
||||
ASSERT(IsExternalTypedDataClassId(cid));
|
||||
ASSERT(IsUnmodifiableTypedDataViewClassId(cid));
|
||||
const intptr_t index =
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderExternal) / 3;
|
||||
(cid - kTypedDataInt8ArrayCid - kTypedDataCidRemainderUnmodifiable) /
|
||||
4;
|
||||
return static_cast<TypedDataElementType>(index);
|
||||
}
|
||||
}
|
||||
@@ -10793,7 +10810,7 @@ class TypedDataBase : public PointerBase {
|
||||
return size;
|
||||
}
|
||||
static const intptr_t kNumElementSizes =
|
||||
(kTypedDataFloat64x2ArrayCid - kTypedDataInt8ArrayCid) / 3 + 1;
|
||||
(kTypedDataFloat64x2ArrayCid - kTypedDataInt8ArrayCid) / 4 + 1;
|
||||
static const intptr_t element_size_table[kNumElementSizes];
|
||||
|
||||
HEAP_OBJECT_IMPLEMENTATION(TypedDataBase, PointerBase);
|
||||
|
||||
@@ -244,6 +244,8 @@ void SetNewSpaceTaggingWord(ObjectPtr to, classid_t cid, uint32_t size) {
|
||||
tags = UntaggedObject::OldAndNotRememberedBit::update(false, tags);
|
||||
tags = UntaggedObject::CanonicalBit::update(false, tags);
|
||||
tags = UntaggedObject::NewBit::update(true, tags);
|
||||
tags = UntaggedObject::ImmutableBit::update(
|
||||
IsUnmodifiableTypedDataViewClassId(cid), tags);
|
||||
#if defined(HASH_IN_OBJECT_HEADER)
|
||||
tags = UntaggedObject::HashTag::update(0, tags);
|
||||
#endif
|
||||
@@ -799,7 +801,8 @@ class FastObjectCopyBase : public ObjectCopyBase {
|
||||
ExternalTypedData::RawCast(to));
|
||||
fast_forward_map_.AddExternalTypedData(
|
||||
ExternalTypedData::RawCast(to));
|
||||
} else if (IsTypedDataViewClassId(cid)) {
|
||||
} else if (IsTypedDataViewClassId(cid) ||
|
||||
IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
// We set the views backing store to `null` to satisfy an assertion in
|
||||
// GCCompactor::VisitTypedDataViewPointers().
|
||||
SetNewSpaceTaggingWord(to, cid, header_size);
|
||||
@@ -1009,7 +1012,8 @@ class SlowObjectCopyBase : public ObjectCopyBase {
|
||||
InitializeExternalTypedDataWithSafepointChecks(
|
||||
thread_, cid, ExternalTypedData::Cast(from), external_to);
|
||||
return external_to.ptr();
|
||||
} else if (IsTypedDataViewClassId(cid)) {
|
||||
} else if (IsTypedDataViewClassId(cid) ||
|
||||
IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
// We set the views backing store to `null` to satisfy an assertion in
|
||||
// GCCompactor::VisitTypedDataViewPointers().
|
||||
InitializeTypedDataView(TypedDataView::RawCast(to));
|
||||
@@ -1125,7 +1129,10 @@ class ObjectCopy : public Base {
|
||||
#undef COPY_TO
|
||||
|
||||
case kByteDataViewCid:
|
||||
#define COPY_TO(clazz) case kTypedData##clazz##ViewCid:
|
||||
case kUnmodifiableByteDataViewCid:
|
||||
#define COPY_TO(clazz) \
|
||||
case kTypedData##clazz##ViewCid: \
|
||||
case kUnmodifiableTypedData##clazz##ViewCid:
|
||||
CLASS_LIST_TYPED_DATA(COPY_TO) {
|
||||
typename Types::TypedDataView casted_from =
|
||||
Types::CastTypedDataView(from);
|
||||
@@ -1979,7 +1986,8 @@ class ObjectGraphCopier {
|
||||
const uword tags = TagsFromUntaggedObject(from.untag());
|
||||
const intptr_t cid = UntaggedObject::ClassIdTag::decode(tags);
|
||||
// External typed data is already initialized.
|
||||
if (!IsExternalTypedDataClassId(cid) && !IsTypedDataViewClassId(cid)) {
|
||||
if (!IsExternalTypedDataClassId(cid) && !IsTypedDataViewClassId(cid) &&
|
||||
!IsUnmodifiableTypedDataViewClassId(cid)) {
|
||||
#if defined(DART_COMPRESSED_POINTERS)
|
||||
const bool compressed = true;
|
||||
#else
|
||||
|
||||
@@ -203,6 +203,8 @@ class ObjectPointerVisitor;
|
||||
RW(Code, null_cast_error_stub_without_fpu_regs_stub) \
|
||||
RW(Code, range_error_stub_with_fpu_regs_stub) \
|
||||
RW(Code, range_error_stub_without_fpu_regs_stub) \
|
||||
RW(Code, write_error_stub_with_fpu_regs_stub) \
|
||||
RW(Code, write_error_stub_without_fpu_regs_stub) \
|
||||
RW(Code, allocate_mint_with_fpu_regs_stub) \
|
||||
RW(Code, allocate_mint_without_fpu_regs_stub) \
|
||||
RW(Code, stack_overflow_stub_with_fpu_regs_stub) \
|
||||
@@ -291,6 +293,8 @@ class ObjectPointerVisitor;
|
||||
NullCastErrorSharedWithoutFPURegs) \
|
||||
DO(range_error_stub_with_fpu_regs_stub, RangeErrorSharedWithFPURegs) \
|
||||
DO(range_error_stub_without_fpu_regs_stub, RangeErrorSharedWithoutFPURegs) \
|
||||
DO(write_error_stub_with_fpu_regs_stub, WriteErrorSharedWithFPURegs) \
|
||||
DO(write_error_stub_without_fpu_regs_stub, WriteErrorSharedWithoutFPURegs) \
|
||||
DO(allocate_mint_with_fpu_regs_stub, AllocateMintSharedWithFPURegs) \
|
||||
DO(allocate_mint_without_fpu_regs_stub, AllocateMintSharedWithoutFPURegs) \
|
||||
DO(stack_overflow_stub_with_fpu_regs_stub, StackOverflowSharedWithFPURegs) \
|
||||
|
||||
@@ -315,7 +315,10 @@ intptr_t UntaggedObject::VisitPointersPredefined(ObjectPointerVisitor* visitor,
|
||||
}
|
||||
#undef RAW_VISITPOINTERS
|
||||
case kByteDataViewCid:
|
||||
#define RAW_VISITPOINTERS(clazz) case kTypedData##clazz##ViewCid:
|
||||
case kUnmodifiableByteDataViewCid:
|
||||
#define RAW_VISITPOINTERS(clazz) \
|
||||
case kTypedData##clazz##ViewCid: \
|
||||
case kUnmodifiableTypedData##clazz##ViewCid:
|
||||
CLASS_LIST_TYPED_DATA(RAW_VISITPOINTERS) {
|
||||
auto raw_obj = static_cast<TypedDataViewPtr>(this);
|
||||
size =
|
||||
|
||||
@@ -163,10 +163,10 @@ class UntaggedObject {
|
||||
kNewBit = 3, // Generational barrier target.
|
||||
kOldBit = 4, // Incremental barrier source.
|
||||
kOldAndNotRememberedBit = 5, // Generational barrier source.
|
||||
kReservedTagPos = 6,
|
||||
kReservedTagSize = 2,
|
||||
kImmutableBit = 6,
|
||||
kReservedBit = 7,
|
||||
|
||||
kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8
|
||||
kSizeTagPos = kReservedBit + 1, // = 8
|
||||
kSizeTagSize = 8,
|
||||
kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16
|
||||
kClassIdTagSize = 16,
|
||||
@@ -252,8 +252,9 @@ class UntaggedObject {
|
||||
class OldAndNotRememberedBit
|
||||
: public BitField<uword, bool, kOldAndNotRememberedBit, 1> {};
|
||||
|
||||
class ReservedBits
|
||||
: public BitField<uword, intptr_t, kReservedTagPos, kReservedTagSize> {};
|
||||
class ImmutableBit : public BitField<uword, bool, kImmutableBit, 1> {};
|
||||
|
||||
class ReservedBit : public BitField<uword, intptr_t, kReservedBit, 1> {};
|
||||
|
||||
// Assumes this is a heap object.
|
||||
bool IsNewObject() const {
|
||||
|
||||
@@ -144,6 +144,10 @@ DEFINE_RUNTIME_ENTRY(RangeError, 2) {
|
||||
Exceptions::ThrowByType(Exceptions::kRange, args);
|
||||
}
|
||||
|
||||
DEFINE_RUNTIME_ENTRY(WriteError, 0) {
|
||||
Exceptions::ThrowUnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
static void NullErrorHelper(Zone* zone,
|
||||
const String& selector,
|
||||
bool is_param_name = false) {
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace dart {
|
||||
V(TraceICCall) \
|
||||
V(PatchStaticCall) \
|
||||
V(RangeError) \
|
||||
V(WriteError) \
|
||||
V(NullError) \
|
||||
V(NullErrorWithSelector) \
|
||||
V(NullCastError) \
|
||||
|
||||
@@ -5711,6 +5711,7 @@ static void GetDefaultClassesAliases(Thread* thread, JSONStream* js) {
|
||||
DEFINE_ADD_VALUE_F_CID(TypedData##clazz) \
|
||||
DEFINE_ADD_VALUE_F_CID(TypedData##clazz##View) \
|
||||
DEFINE_ADD_VALUE_F_CID(ExternalTypedData##clazz) \
|
||||
DEFINE_ADD_VALUE_F_CID(UnmodifiableTypedData##clazz##View) \
|
||||
}
|
||||
CLASS_LIST_TYPED_DATA(DEFINE_ADD_MAP_KEY)
|
||||
#undef DEFINE_ADD_MAP_KEY
|
||||
|
||||
@@ -120,6 +120,8 @@ namespace dart {
|
||||
V(NullCastErrorSharedWithoutFPURegs) \
|
||||
V(RangeErrorSharedWithFPURegs) \
|
||||
V(RangeErrorSharedWithoutFPURegs) \
|
||||
V(WriteErrorSharedWithFPURegs) \
|
||||
V(WriteErrorSharedWithoutFPURegs) \
|
||||
V(StackOverflowSharedWithFPURegs) \
|
||||
V(StackOverflowSharedWithoutFPURegs) \
|
||||
V(DoubleToInteger) \
|
||||
|
||||
@@ -278,6 +278,7 @@ class ObjectPointerVisitor;
|
||||
V(_ByteBuffer, "_ByteBuffer") \
|
||||
V(_ByteBufferDot_New, "_ByteBuffer._New") \
|
||||
V(_ByteDataView, "_ByteDataView") \
|
||||
V(_UnmodifiableByteDataView, "_UnmodifiableByteDataView") \
|
||||
V(_CapabilityImpl, "_CapabilityImpl") \
|
||||
V(_ClassMirror, "_ClassMirror") \
|
||||
V(_Closure, "_Closure") \
|
||||
@@ -305,6 +306,20 @@ class ObjectPointerVisitor;
|
||||
V(_ExternalUint8ClampedArray, "_ExternalUint8ClampedArray") \
|
||||
V(_FinalizerImpl, "_FinalizerImpl") \
|
||||
V(_NativeFinalizer, "_NativeFinalizer") \
|
||||
V(_UnmodifiableInt8ArrayView, "_UnmodifiableInt8ArrayView") \
|
||||
V(_UnmodifiableInt16ArrayView, "_UnmodifiableInt16ArrayView") \
|
||||
V(_UnmodifiableInt32ArrayView, "_UnmodifiableInt32ArrayView") \
|
||||
V(_UnmodifiableInt64ArrayView, "_UnmodifiableInt64ArrayView") \
|
||||
V(_UnmodifiableUint8ClampedArrayView, "_UnmodifiableUint8ClampedArrayView") \
|
||||
V(_UnmodifiableUint8ArrayView, "_UnmodifiableUint8ArrayView") \
|
||||
V(_UnmodifiableUint16ArrayView, "_UnmodifiableUint16ArrayView") \
|
||||
V(_UnmodifiableUint32ArrayView, "_UnmodifiableUint32ArrayView") \
|
||||
V(_UnmodifiableUint64ArrayView, "_UnmodifiableUint64ArrayView") \
|
||||
V(_UnmodifiableFloat32ArrayView, "_UnmodifiableFloat32ArrayView") \
|
||||
V(_UnmodifiableFloat64ArrayView, "_UnmodifiableFloat64ArrayView") \
|
||||
V(_UnmodifiableInt32x4ArrayView, "_UnmodifiableInt32x4ArrayView") \
|
||||
V(_UnmodifiableFloat32x4ArrayView, "_UnmodifiableFloat32x4ArrayView") \
|
||||
V(_UnmodifiableFloat64x2ArrayView, "_UnmodifiableFloat64x2ArrayView") \
|
||||
V(_Float32ArrayFactory, "Float32List.") \
|
||||
V(_Float32ArrayView, "_Float32ArrayView") \
|
||||
V(_Float32List, "_Float32List") \
|
||||
|
||||
@@ -112,6 +112,9 @@ class ObjectPtr {
|
||||
bool IsTypedDataView##clazz() const { \
|
||||
return ((GetClassId() == kTypedData##clazz##ViewCid)); \
|
||||
} \
|
||||
bool IsUnmodifiableTypedDataView##clazz() const { \
|
||||
return ((GetClassId() == kUnmodifiableTypedData##clazz##ViewCid)); \
|
||||
} \
|
||||
bool IsExternalTypedData##clazz() const { \
|
||||
return ((GetClassId() == kExternalTypedData##clazz##Cid)); \
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@ class Thread;
|
||||
StubCode::RangeErrorSharedWithoutFPURegs().ptr(), nullptr) \
|
||||
V(CodePtr, range_error_shared_with_fpu_regs_stub_, \
|
||||
StubCode::RangeErrorSharedWithFPURegs().ptr(), nullptr) \
|
||||
V(CodePtr, write_error_shared_without_fpu_regs_stub_, \
|
||||
StubCode::WriteErrorSharedWithoutFPURegs().ptr(), nullptr) \
|
||||
V(CodePtr, write_error_shared_with_fpu_regs_stub_, \
|
||||
StubCode::WriteErrorSharedWithFPURegs().ptr(), nullptr) \
|
||||
V(CodePtr, allocate_mint_with_fpu_regs_stub_, \
|
||||
StubCode::AllocateMintSharedWithFPURegs().ptr(), nullptr) \
|
||||
V(CodePtr, allocate_mint_without_fpu_regs_stub_, \
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:_js_helper' show patch;
|
||||
import 'dart:_native_typed_data';
|
||||
import "dart:_internal" show UnmodifiableListBase;
|
||||
|
||||
@patch
|
||||
class ByteData {
|
||||
@@ -188,3 +189,450 @@ class Float64x2 {
|
||||
@patch
|
||||
factory Float64x2.fromFloat32x4(Float32x4 v) = NativeFloat64x2.fromFloat32x4;
|
||||
}
|
||||
|
||||
/// A read-only view of a [ByteBuffer].
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteBufferView.
|
||||
class _UnmodifiableByteBufferView implements ByteBuffer {
|
||||
final ByteBuffer _data;
|
||||
|
||||
_UnmodifiableByteBufferView(ByteBuffer data) : _data = data;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
Uint8List asUint8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ListView(_data.asUint8List(offsetInBytes, length));
|
||||
|
||||
Int8List asInt8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt8ListView(_data.asInt8List(offsetInBytes, length));
|
||||
|
||||
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ClampedListView(
|
||||
_data.asUint8ClampedList(offsetInBytes, length));
|
||||
|
||||
Uint16List asUint16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint16ListView(_data.asUint16List(offsetInBytes, length));
|
||||
|
||||
Int16List asInt16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt16ListView(_data.asInt16List(offsetInBytes, length));
|
||||
|
||||
Uint32List asUint32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint32ListView(_data.asUint32List(offsetInBytes, length));
|
||||
|
||||
Int32List asInt32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32ListView(_data.asInt32List(offsetInBytes, length));
|
||||
|
||||
Uint64List asUint64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint64ListView(_data.asUint64List(offsetInBytes, length));
|
||||
|
||||
Int64List asInt64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt64ListView(_data.asInt64List(offsetInBytes, length));
|
||||
|
||||
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32x4ListView(
|
||||
_data.asInt32x4List(offsetInBytes, length));
|
||||
|
||||
Float32List asFloat32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32ListView(
|
||||
_data.asFloat32List(offsetInBytes, length));
|
||||
|
||||
Float64List asFloat64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64ListView(
|
||||
_data.asFloat64List(offsetInBytes, length));
|
||||
|
||||
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32x4ListView(
|
||||
_data.asFloat32x4List(offsetInBytes, length));
|
||||
|
||||
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64x2ListView(
|
||||
_data.asFloat64x2List(offsetInBytes, length));
|
||||
|
||||
ByteData asByteData([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableByteDataView(_data.asByteData(offsetInBytes, length));
|
||||
}
|
||||
|
||||
/// A read-only view of a [ByteData].
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteDataView.
|
||||
class _UnmodifiableByteDataView implements ByteData {
|
||||
final ByteData _data;
|
||||
|
||||
_UnmodifiableByteDataView(ByteData data) : _data = data;
|
||||
|
||||
int getInt8(int byteOffset) => _data.getInt8(byteOffset);
|
||||
|
||||
void setInt8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getUint8(int byteOffset) => _data.getUint8(byteOffset);
|
||||
|
||||
void setUint8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getInt16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt16(byteOffset, endian);
|
||||
|
||||
void setInt16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint16(byteOffset, endian);
|
||||
|
||||
void setUint16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt32(byteOffset, endian);
|
||||
|
||||
void setInt32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint32(byteOffset, endian);
|
||||
|
||||
void setUint32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt64(byteOffset, endian);
|
||||
|
||||
void setInt64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint64(byteOffset, endian);
|
||||
|
||||
void setUint64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat32(byteOffset, endian);
|
||||
|
||||
void setFloat32(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat64(byteOffset, endian);
|
||||
|
||||
void setFloat64(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
void _unsupported() {
|
||||
throw new UnsupportedError(
|
||||
"An UnmodifiableByteDataView may not be modified");
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _UnmodifiableListMixin<N, L extends List<N>,
|
||||
TD extends TypedData> {
|
||||
L get _list;
|
||||
TD get _data => (_list as TD);
|
||||
|
||||
int get length => _list.length;
|
||||
|
||||
N operator [](int index) => _list[index];
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
L _createList(int length);
|
||||
|
||||
L sublist(int start, [int? end]) {
|
||||
// NNBD: Spurious error at `end`, `checkValidRange` is legacy.
|
||||
int endIndex = RangeError.checkValidRange(start, end!, length);
|
||||
int sublistLength = endIndex - start;
|
||||
L result = _createList(sublistLength);
|
||||
result.setRange(0, sublistLength, _list, start);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// View of a [Uint8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ListView.
|
||||
class _UnmodifiableUint8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8List, Uint8List>
|
||||
implements UnmodifiableUint8ListView {
|
||||
final Uint8List _list;
|
||||
_UnmodifiableUint8ListView(Uint8List list) : _list = list;
|
||||
|
||||
Uint8List _createList(int length) => Uint8List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt8ListView.
|
||||
class _UnmodifiableInt8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int8List, Int8List>
|
||||
implements UnmodifiableInt8ListView {
|
||||
final Int8List _list;
|
||||
_UnmodifiableInt8ListView(Int8List list) : _list = list;
|
||||
|
||||
Int8List _createList(int length) => Int8List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint8ClampedList] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ClampedListView.
|
||||
class _UnmodifiableUint8ClampedListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8ClampedList, Uint8ClampedList>
|
||||
implements UnmodifiableUint8ClampedListView {
|
||||
final Uint8ClampedList _list;
|
||||
_UnmodifiableUint8ClampedListView(Uint8ClampedList list) : _list = list;
|
||||
|
||||
Uint8ClampedList _createList(int length) => Uint8ClampedList(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint16ListView.
|
||||
class _UnmodifiableUint16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint16List, Uint16List>
|
||||
implements UnmodifiableUint16ListView {
|
||||
final Uint16List _list;
|
||||
_UnmodifiableUint16ListView(Uint16List list) : _list = list;
|
||||
|
||||
Uint16List _createList(int length) => Uint16List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt16ListView.
|
||||
class _UnmodifiableInt16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int16List, Int16List>
|
||||
implements UnmodifiableInt16ListView {
|
||||
final Int16List _list;
|
||||
_UnmodifiableInt16ListView(Int16List list) : _list = list;
|
||||
|
||||
Int16List _createList(int length) => Int16List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint32ListView.
|
||||
class _UnmodifiableUint32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint32List, Uint32List>
|
||||
implements UnmodifiableUint32ListView {
|
||||
final Uint32List _list;
|
||||
_UnmodifiableUint32ListView(Uint32List list) : _list = list;
|
||||
|
||||
Uint32List _createList(int length) => Uint32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32ListView.
|
||||
class _UnmodifiableInt32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int32List, Int32List>
|
||||
implements UnmodifiableInt32ListView {
|
||||
final Int32List _list;
|
||||
_UnmodifiableInt32ListView(Int32List list) : _list = list;
|
||||
|
||||
Int32List _createList(int length) => Int32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint64ListView.
|
||||
class _UnmodifiableUint64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint64List, Uint64List>
|
||||
implements UnmodifiableUint64ListView {
|
||||
final Uint64List _list;
|
||||
_UnmodifiableUint64ListView(Uint64List list) : _list = list;
|
||||
|
||||
Uint64List _createList(int length) => Uint64List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt64ListView.
|
||||
class _UnmodifiableInt64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int64List, Int64List>
|
||||
implements UnmodifiableInt64ListView {
|
||||
final Int64List _list;
|
||||
_UnmodifiableInt64ListView(Int64List list) : _list = list;
|
||||
|
||||
Int64List _createList(int length) => Int64List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32x4ListView.
|
||||
class _UnmodifiableInt32x4ListView extends UnmodifiableListBase<Int32x4>
|
||||
with _UnmodifiableListMixin<Int32x4, Int32x4List, Int32x4List>
|
||||
implements UnmodifiableInt32x4ListView {
|
||||
final Int32x4List _list;
|
||||
_UnmodifiableInt32x4ListView(Int32x4List list) : _list = list;
|
||||
|
||||
Int32x4List _createList(int length) => Int32x4List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32x4ListView.
|
||||
class _UnmodifiableFloat32x4ListView extends UnmodifiableListBase<Float32x4>
|
||||
with _UnmodifiableListMixin<Float32x4, Float32x4List, Float32x4List>
|
||||
implements UnmodifiableFloat32x4ListView {
|
||||
final Float32x4List _list;
|
||||
_UnmodifiableFloat32x4ListView(Float32x4List list) : _list = list;
|
||||
|
||||
Float32x4List _createList(int length) => Float32x4List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float64x2List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64x2ListView.
|
||||
class _UnmodifiableFloat64x2ListView extends UnmodifiableListBase<Float64x2>
|
||||
with _UnmodifiableListMixin<Float64x2, Float64x2List, Float64x2List>
|
||||
implements UnmodifiableFloat64x2ListView {
|
||||
final Float64x2List _list;
|
||||
_UnmodifiableFloat64x2ListView(Float64x2List list) : _list = list;
|
||||
|
||||
Float64x2List _createList(int length) => Float64x2List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32ListView.
|
||||
class _UnmodifiableFloat32ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float32List, Float32List>
|
||||
implements UnmodifiableFloat32ListView {
|
||||
final Float32List _list;
|
||||
_UnmodifiableFloat32ListView(Float32List list) : _list = list;
|
||||
|
||||
Float32List _createList(int length) => Float32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64ListView.
|
||||
class _UnmodifiableFloat64ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float64List, Float64List>
|
||||
implements UnmodifiableFloat64ListView {
|
||||
final Float64List _list;
|
||||
_UnmodifiableFloat64ListView(Float64List list) : _list = list;
|
||||
|
||||
Float64List _createList(int length) => Float64List(length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteBufferView implements Uint8List {
|
||||
factory UnmodifiableByteBufferView(ByteBuffer data) =
|
||||
_UnmodifiableByteBufferView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteDataView implements Uint8List {
|
||||
factory UnmodifiableByteDataView(ByteData data) = _UnmodifiableByteDataView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ListView implements Uint8List {
|
||||
factory UnmodifiableUint8ListView(Uint8List list) =
|
||||
_UnmodifiableUint8ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt8ListView implements Int8List {
|
||||
factory UnmodifiableInt8ListView(Int8List list) = _UnmodifiableInt8ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ClampedListView implements Uint8ClampedList {
|
||||
factory UnmodifiableUint8ClampedListView(Uint8ClampedList list) =
|
||||
_UnmodifiableUint8ClampedListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint16ListView implements Uint16List {
|
||||
factory UnmodifiableUint16ListView(Uint16List list) =
|
||||
_UnmodifiableUint16ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt16ListView implements Int16List {
|
||||
factory UnmodifiableInt16ListView(Int16List list) =
|
||||
_UnmodifiableInt16ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint32ListView implements Uint32List {
|
||||
factory UnmodifiableUint32ListView(Uint32List list) =
|
||||
_UnmodifiableUint32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32ListView implements Int32List {
|
||||
factory UnmodifiableInt32ListView(Int32List list) =
|
||||
_UnmodifiableInt32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint64ListView implements Uint64List {
|
||||
factory UnmodifiableUint64ListView(Uint64List list) =
|
||||
_UnmodifiableUint64ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt64ListView implements Int64List {
|
||||
factory UnmodifiableInt64ListView(Int64List list) =
|
||||
_UnmodifiableInt64ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32x4ListView implements Int32x4List {
|
||||
factory UnmodifiableInt32x4ListView(Int32x4List list) =
|
||||
_UnmodifiableInt32x4ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32x4ListView implements Float32x4List {
|
||||
factory UnmodifiableFloat32x4ListView(Float32x4List list) =
|
||||
_UnmodifiableFloat32x4ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64x2ListView implements Float64x2List {
|
||||
factory UnmodifiableFloat64x2ListView(Float64x2List list) =
|
||||
_UnmodifiableFloat64x2ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32ListView implements Float32List {
|
||||
factory UnmodifiableFloat32ListView(Float32List list) =
|
||||
_UnmodifiableFloat32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64ListView implements Float64List {
|
||||
factory UnmodifiableFloat64ListView(Float64List list) =
|
||||
_UnmodifiableFloat64ListView;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:_js_helper' show patch;
|
||||
import 'dart:_native_typed_data';
|
||||
import "dart:_internal" show UnmodifiableListBase;
|
||||
|
||||
@patch
|
||||
class ByteData {
|
||||
@@ -188,3 +189,450 @@ class Float64x2 {
|
||||
@patch
|
||||
factory Float64x2.fromFloat32x4(Float32x4 v) = NativeFloat64x2.fromFloat32x4;
|
||||
}
|
||||
|
||||
/// A read-only view of a [ByteBuffer].
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteBufferView.
|
||||
class _UnmodifiableByteBufferView implements ByteBuffer {
|
||||
final ByteBuffer _data;
|
||||
|
||||
_UnmodifiableByteBufferView(ByteBuffer data) : _data = data;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
Uint8List asUint8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ListView(_data.asUint8List(offsetInBytes, length));
|
||||
|
||||
Int8List asInt8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt8ListView(_data.asInt8List(offsetInBytes, length));
|
||||
|
||||
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ClampedListView(
|
||||
_data.asUint8ClampedList(offsetInBytes, length));
|
||||
|
||||
Uint16List asUint16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint16ListView(_data.asUint16List(offsetInBytes, length));
|
||||
|
||||
Int16List asInt16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt16ListView(_data.asInt16List(offsetInBytes, length));
|
||||
|
||||
Uint32List asUint32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint32ListView(_data.asUint32List(offsetInBytes, length));
|
||||
|
||||
Int32List asInt32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32ListView(_data.asInt32List(offsetInBytes, length));
|
||||
|
||||
Uint64List asUint64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint64ListView(_data.asUint64List(offsetInBytes, length));
|
||||
|
||||
Int64List asInt64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt64ListView(_data.asInt64List(offsetInBytes, length));
|
||||
|
||||
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32x4ListView(
|
||||
_data.asInt32x4List(offsetInBytes, length));
|
||||
|
||||
Float32List asFloat32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32ListView(
|
||||
_data.asFloat32List(offsetInBytes, length));
|
||||
|
||||
Float64List asFloat64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64ListView(
|
||||
_data.asFloat64List(offsetInBytes, length));
|
||||
|
||||
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32x4ListView(
|
||||
_data.asFloat32x4List(offsetInBytes, length));
|
||||
|
||||
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64x2ListView(
|
||||
_data.asFloat64x2List(offsetInBytes, length));
|
||||
|
||||
ByteData asByteData([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableByteDataView(_data.asByteData(offsetInBytes, length));
|
||||
}
|
||||
|
||||
/// A read-only view of a [ByteData].
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteDataView.
|
||||
class _UnmodifiableByteDataView implements ByteData {
|
||||
final ByteData _data;
|
||||
|
||||
_UnmodifiableByteDataView(ByteData data) : _data = data;
|
||||
|
||||
int getInt8(int byteOffset) => _data.getInt8(byteOffset);
|
||||
|
||||
void setInt8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getUint8(int byteOffset) => _data.getUint8(byteOffset);
|
||||
|
||||
void setUint8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getInt16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt16(byteOffset, endian);
|
||||
|
||||
void setInt16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint16(byteOffset, endian);
|
||||
|
||||
void setUint16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt32(byteOffset, endian);
|
||||
|
||||
void setInt32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint32(byteOffset, endian);
|
||||
|
||||
void setUint32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt64(byteOffset, endian);
|
||||
|
||||
void setInt64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint64(byteOffset, endian);
|
||||
|
||||
void setUint64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat32(byteOffset, endian);
|
||||
|
||||
void setFloat32(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat64(byteOffset, endian);
|
||||
|
||||
void setFloat64(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
void _unsupported() {
|
||||
throw new UnsupportedError(
|
||||
"An UnmodifiableByteDataView may not be modified");
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _UnmodifiableListMixin<N, L extends List<N>,
|
||||
TD extends TypedData> {
|
||||
L get _list;
|
||||
TD get _data => (_list as TD);
|
||||
|
||||
int get length => _list.length;
|
||||
|
||||
N operator [](int index) => _list[index];
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
L _createList(int length);
|
||||
|
||||
L sublist(int start, [int? end]) {
|
||||
// NNBD: Spurious error at `end`, `checkValidRange` is legacy.
|
||||
int endIndex = RangeError.checkValidRange(start, end!, length);
|
||||
int sublistLength = endIndex - start;
|
||||
L result = _createList(sublistLength);
|
||||
result.setRange(0, sublistLength, _list, start);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// View of a [Uint8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ListView.
|
||||
class _UnmodifiableUint8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8List, Uint8List>
|
||||
implements UnmodifiableUint8ListView {
|
||||
final Uint8List _list;
|
||||
_UnmodifiableUint8ListView(Uint8List list) : _list = list;
|
||||
|
||||
Uint8List _createList(int length) => Uint8List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt8ListView.
|
||||
class _UnmodifiableInt8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int8List, Int8List>
|
||||
implements UnmodifiableInt8ListView {
|
||||
final Int8List _list;
|
||||
_UnmodifiableInt8ListView(Int8List list) : _list = list;
|
||||
|
||||
Int8List _createList(int length) => Int8List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint8ClampedList] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ClampedListView.
|
||||
class _UnmodifiableUint8ClampedListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8ClampedList, Uint8ClampedList>
|
||||
implements UnmodifiableUint8ClampedListView {
|
||||
final Uint8ClampedList _list;
|
||||
_UnmodifiableUint8ClampedListView(Uint8ClampedList list) : _list = list;
|
||||
|
||||
Uint8ClampedList _createList(int length) => Uint8ClampedList(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint16ListView.
|
||||
class _UnmodifiableUint16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint16List, Uint16List>
|
||||
implements UnmodifiableUint16ListView {
|
||||
final Uint16List _list;
|
||||
_UnmodifiableUint16ListView(Uint16List list) : _list = list;
|
||||
|
||||
Uint16List _createList(int length) => Uint16List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt16ListView.
|
||||
class _UnmodifiableInt16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int16List, Int16List>
|
||||
implements UnmodifiableInt16ListView {
|
||||
final Int16List _list;
|
||||
_UnmodifiableInt16ListView(Int16List list) : _list = list;
|
||||
|
||||
Int16List _createList(int length) => Int16List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint32ListView.
|
||||
class _UnmodifiableUint32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint32List, Uint32List>
|
||||
implements UnmodifiableUint32ListView {
|
||||
final Uint32List _list;
|
||||
_UnmodifiableUint32ListView(Uint32List list) : _list = list;
|
||||
|
||||
Uint32List _createList(int length) => Uint32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32ListView.
|
||||
class _UnmodifiableInt32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int32List, Int32List>
|
||||
implements UnmodifiableInt32ListView {
|
||||
final Int32List _list;
|
||||
_UnmodifiableInt32ListView(Int32List list) : _list = list;
|
||||
|
||||
Int32List _createList(int length) => Int32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Uint64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint64ListView.
|
||||
class _UnmodifiableUint64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint64List, Uint64List>
|
||||
implements UnmodifiableUint64ListView {
|
||||
final Uint64List _list;
|
||||
_UnmodifiableUint64ListView(Uint64List list) : _list = list;
|
||||
|
||||
Uint64List _createList(int length) => Uint64List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt64ListView.
|
||||
class _UnmodifiableInt64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int64List, Int64List>
|
||||
implements UnmodifiableInt64ListView {
|
||||
final Int64List _list;
|
||||
_UnmodifiableInt64ListView(Int64List list) : _list = list;
|
||||
|
||||
Int64List _createList(int length) => Int64List(length);
|
||||
}
|
||||
|
||||
/// View of a [Int32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32x4ListView.
|
||||
class _UnmodifiableInt32x4ListView extends UnmodifiableListBase<Int32x4>
|
||||
with _UnmodifiableListMixin<Int32x4, Int32x4List, Int32x4List>
|
||||
implements UnmodifiableInt32x4ListView {
|
||||
final Int32x4List _list;
|
||||
_UnmodifiableInt32x4ListView(Int32x4List list) : _list = list;
|
||||
|
||||
Int32x4List _createList(int length) => Int32x4List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32x4ListView.
|
||||
class _UnmodifiableFloat32x4ListView extends UnmodifiableListBase<Float32x4>
|
||||
with _UnmodifiableListMixin<Float32x4, Float32x4List, Float32x4List>
|
||||
implements UnmodifiableFloat32x4ListView {
|
||||
final Float32x4List _list;
|
||||
_UnmodifiableFloat32x4ListView(Float32x4List list) : _list = list;
|
||||
|
||||
Float32x4List _createList(int length) => Float32x4List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float64x2List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64x2ListView.
|
||||
class _UnmodifiableFloat64x2ListView extends UnmodifiableListBase<Float64x2>
|
||||
with _UnmodifiableListMixin<Float64x2, Float64x2List, Float64x2List>
|
||||
implements UnmodifiableFloat64x2ListView {
|
||||
final Float64x2List _list;
|
||||
_UnmodifiableFloat64x2ListView(Float64x2List list) : _list = list;
|
||||
|
||||
Float64x2List _createList(int length) => Float64x2List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32ListView.
|
||||
class _UnmodifiableFloat32ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float32List, Float32List>
|
||||
implements UnmodifiableFloat32ListView {
|
||||
final Float32List _list;
|
||||
_UnmodifiableFloat32ListView(Float32List list) : _list = list;
|
||||
|
||||
Float32List _createList(int length) => Float32List(length);
|
||||
}
|
||||
|
||||
/// View of a [Float64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64ListView.
|
||||
class _UnmodifiableFloat64ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float64List, Float64List>
|
||||
implements UnmodifiableFloat64ListView {
|
||||
final Float64List _list;
|
||||
_UnmodifiableFloat64ListView(Float64List list) : _list = list;
|
||||
|
||||
Float64List _createList(int length) => Float64List(length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteBufferView implements Uint8List {
|
||||
factory UnmodifiableByteBufferView(ByteBuffer data) =
|
||||
_UnmodifiableByteBufferView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteDataView implements Uint8List {
|
||||
factory UnmodifiableByteDataView(ByteData data) = _UnmodifiableByteDataView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ListView implements Uint8List {
|
||||
factory UnmodifiableUint8ListView(Uint8List list) =
|
||||
_UnmodifiableUint8ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt8ListView implements Int8List {
|
||||
factory UnmodifiableInt8ListView(Int8List list) = _UnmodifiableInt8ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ClampedListView implements Uint8ClampedList {
|
||||
factory UnmodifiableUint8ClampedListView(Uint8ClampedList list) =
|
||||
_UnmodifiableUint8ClampedListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint16ListView implements Uint16List {
|
||||
factory UnmodifiableUint16ListView(Uint16List list) =
|
||||
_UnmodifiableUint16ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt16ListView implements Int16List {
|
||||
factory UnmodifiableInt16ListView(Int16List list) =
|
||||
_UnmodifiableInt16ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint32ListView implements Uint32List {
|
||||
factory UnmodifiableUint32ListView(Uint32List list) =
|
||||
_UnmodifiableUint32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32ListView implements Int32List {
|
||||
factory UnmodifiableInt32ListView(Int32List list) =
|
||||
_UnmodifiableInt32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint64ListView implements Uint64List {
|
||||
factory UnmodifiableUint64ListView(Uint64List list) =
|
||||
_UnmodifiableUint64ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt64ListView implements Int64List {
|
||||
factory UnmodifiableInt64ListView(Int64List list) =
|
||||
_UnmodifiableInt64ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32x4ListView implements Int32x4List {
|
||||
factory UnmodifiableInt32x4ListView(Int32x4List list) =
|
||||
_UnmodifiableInt32x4ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32x4ListView implements Float32x4List {
|
||||
factory UnmodifiableFloat32x4ListView(Float32x4List list) =
|
||||
_UnmodifiableFloat32x4ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64x2ListView implements Float64x2List {
|
||||
factory UnmodifiableFloat64x2ListView(Float64x2List list) =
|
||||
_UnmodifiableFloat64x2ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32ListView implements Float32List {
|
||||
factory UnmodifiableFloat32ListView(Float32List list) =
|
||||
_UnmodifiableFloat32ListView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64ListView implements Float64List {
|
||||
factory UnmodifiableFloat64ListView(Float64List list) =
|
||||
_UnmodifiableFloat64ListView;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ import "dart:_internal"
|
||||
TakeWhileIterable,
|
||||
WhereIterable,
|
||||
WhereTypeIterable,
|
||||
patch;
|
||||
patch,
|
||||
unsafeCast;
|
||||
|
||||
import "dart:collection" show ListBase;
|
||||
|
||||
@@ -67,6 +68,7 @@ abstract class _TypedListBase {
|
||||
int get elementSizeInBytes;
|
||||
int get offsetInBytes;
|
||||
_ByteBuffer get buffer;
|
||||
_TypedList get _typedData;
|
||||
|
||||
// Method(s) implementing the Collection interface.
|
||||
String join([String separator = ""]) {
|
||||
@@ -2043,6 +2045,8 @@ abstract class _TypedList extends _TypedListBase {
|
||||
|
||||
// Internal utility methods.
|
||||
|
||||
_TypedList get _typedData => this;
|
||||
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", "dart:core#_Smi")
|
||||
@pragma("vm:external-name", "TypedData_GetInt8")
|
||||
@@ -5107,3 +5111,479 @@ void _offsetAlignmentCheck(int offset, int alignment) {
|
||||
'BYTES_PER_ELEMENT ($alignment)');
|
||||
}
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteBufferView implements Uint8List {
|
||||
factory UnmodifiableByteBufferView(ByteBuffer data) =
|
||||
_UnmodifiableByteBufferView;
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableByteDataView implements ByteData {
|
||||
factory UnmodifiableByteDataView(ByteData data) =>
|
||||
new _UnmodifiableByteDataView._((data as _ByteDataView).buffer._data,
|
||||
data.offsetInBytes, data.lengthInBytes);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ListView implements Uint8List {
|
||||
factory UnmodifiableUint8ListView(Uint8List list) =>
|
||||
new _UnmodifiableUint8ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt8ListView implements Int8List {
|
||||
factory UnmodifiableInt8ListView(Int8List list) =>
|
||||
new _UnmodifiableInt8ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint8ClampedListView implements Uint8ClampedList {
|
||||
factory UnmodifiableUint8ClampedListView(Uint8ClampedList list) =>
|
||||
new _UnmodifiableUint8ClampedArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint16ListView implements Uint16List {
|
||||
factory UnmodifiableUint16ListView(Uint16List list) =>
|
||||
new _UnmodifiableUint16ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt16ListView implements Int16List {
|
||||
factory UnmodifiableInt16ListView(Int16List list) =>
|
||||
new _UnmodifiableInt16ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint32ListView implements Uint32List {
|
||||
factory UnmodifiableUint32ListView(Uint32List list) =>
|
||||
new _UnmodifiableUint32ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32ListView implements Int32List {
|
||||
factory UnmodifiableInt32ListView(Int32List list) =>
|
||||
new _UnmodifiableInt32ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableUint64ListView implements Uint64List {
|
||||
factory UnmodifiableUint64ListView(Uint64List list) =>
|
||||
new _UnmodifiableUint64ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt64ListView implements Int64List {
|
||||
factory UnmodifiableInt64ListView(Int64List list) =>
|
||||
new _UnmodifiableInt64ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableInt32x4ListView implements Int32x4List {
|
||||
factory UnmodifiableInt32x4ListView(Int32x4List list) =>
|
||||
new _UnmodifiableInt32x4ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32x4ListView implements Float32x4List {
|
||||
factory UnmodifiableFloat32x4ListView(Float32x4List list) =>
|
||||
new _UnmodifiableFloat32x4ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64x2ListView implements Float64x2List {
|
||||
factory UnmodifiableFloat64x2ListView(Float64x2List list) =>
|
||||
new _UnmodifiableFloat64x2ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat32ListView implements Float32List {
|
||||
factory UnmodifiableFloat32ListView(Float32List list) =>
|
||||
new _UnmodifiableFloat32ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@patch
|
||||
abstract class UnmodifiableFloat64ListView implements Float64List {
|
||||
factory UnmodifiableFloat64ListView(Float64List list) =>
|
||||
new _UnmodifiableFloat64ArrayView._(
|
||||
unsafeCast<_TypedListBase>(list)._typedData,
|
||||
list.offsetInBytes,
|
||||
list.length);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableInt8ArrayView extends _Int8ArrayView
|
||||
implements UnmodifiableInt8ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableInt8ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Int8ArrayView_new")
|
||||
external factory _UnmodifiableInt8ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableUint8ArrayView extends _Uint8ArrayView
|
||||
implements UnmodifiableUint8ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableUint8ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Uint8ArrayView_new")
|
||||
external factory _UnmodifiableUint8ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableUint8ClampedArrayView extends _Uint8ClampedArrayView
|
||||
implements UnmodifiableUint8ClampedListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableUint8ClampedArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Uint8ClampedArrayView_new")
|
||||
external factory _UnmodifiableUint8ClampedArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableInt16ArrayView extends _Int16ArrayView
|
||||
implements UnmodifiableInt16ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableInt16ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Int16ArrayView_new")
|
||||
external factory _UnmodifiableInt16ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableUint16ArrayView extends _Uint16ArrayView
|
||||
implements UnmodifiableUint16ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableUint16ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Uint16ArrayView_new")
|
||||
external factory _UnmodifiableUint16ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableInt32ArrayView extends _Int32ArrayView
|
||||
implements UnmodifiableInt32ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableInt32ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Int32ArrayView_new")
|
||||
external factory _UnmodifiableInt32ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableUint32ArrayView extends _Uint32ArrayView
|
||||
implements UnmodifiableUint32ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableUint32ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Uint32ArrayView_new")
|
||||
external factory _UnmodifiableUint32ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableInt64ArrayView extends _Int64ArrayView
|
||||
implements UnmodifiableInt64ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableInt64ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Int64ArrayView_new")
|
||||
external factory _UnmodifiableInt64ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableUint64ArrayView extends _Uint64ArrayView
|
||||
implements UnmodifiableUint64ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableUint64ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Uint64ArrayView_new")
|
||||
external factory _UnmodifiableUint64ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableFloat32ArrayView extends _Float32ArrayView
|
||||
implements UnmodifiableFloat32ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableFloat32ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Float32ArrayView_new")
|
||||
external factory _UnmodifiableFloat32ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, double value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableFloat64ArrayView extends _Float64ArrayView
|
||||
implements UnmodifiableFloat64ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableFloat64ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Float64ArrayView_new")
|
||||
external factory _UnmodifiableFloat64ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, double value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableFloat32x4ArrayView extends _Float32x4ArrayView
|
||||
implements UnmodifiableFloat32x4ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableFloat32x4ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Float32x4ArrayView_new")
|
||||
external factory _UnmodifiableFloat32x4ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, Float32x4 value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableInt32x4ArrayView extends _Int32x4ArrayView
|
||||
implements UnmodifiableInt32x4ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableInt32x4ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Int32x4ArrayView_new")
|
||||
external factory _UnmodifiableInt32x4ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, Int32x4 value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableFloat64x2ArrayView extends _Float64x2ArrayView
|
||||
implements UnmodifiableFloat64x2ListView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableFloat64x2ArrayView)
|
||||
@pragma("vm:external-name", "TypedDataView_Float64x2ArrayView_new")
|
||||
external factory _UnmodifiableFloat64x2ArrayView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void operator []=(int index, Float64x2 value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
class _UnmodifiableByteDataView extends _ByteDataView
|
||||
implements UnmodifiableByteDataView {
|
||||
@pragma("vm:recognized", "other")
|
||||
@pragma("vm:exact-result-type", _UnmodifiableByteDataView)
|
||||
@pragma("vm:external-name", "TypedDataView_ByteDataView_new")
|
||||
external factory _UnmodifiableByteDataView._(
|
||||
_TypedList buffer, int offsetInBytes, int length);
|
||||
|
||||
void setInt8(int byteOffset, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setUint8(int byteOffset, int value) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setInt16(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setUint16(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setInt32(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setUint32(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setInt64(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setUint64(int byteOffset, int value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setFloat32(int byteOffset, double value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setFloat64(int byteOffset, double value, [Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
void setFloat32x4(int byteOffset, Float32x4 value,
|
||||
[Endian endian = Endian.big]) {
|
||||
throw new UnsupportedError("Cannot modify an unmodifiable list");
|
||||
}
|
||||
|
||||
_ByteBuffer get buffer => new _UnmodifiableByteBufferView(_typedData.buffer);
|
||||
}
|
||||
|
||||
class _UnmodifiableByteBufferView extends _ByteBuffer
|
||||
implements UnmodifiableByteBufferView {
|
||||
_UnmodifiableByteBufferView(_ByteBuffer data) : super(data._data);
|
||||
|
||||
Uint8List asUint8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ListView(super.asUint8List(offsetInBytes, length));
|
||||
|
||||
Int8List asInt8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt8ListView(super.asInt8List(offsetInBytes, length));
|
||||
|
||||
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ClampedListView(
|
||||
super.asUint8ClampedList(offsetInBytes, length));
|
||||
|
||||
Uint16List asUint16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint16ListView(super.asUint16List(offsetInBytes, length));
|
||||
|
||||
Int16List asInt16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt16ListView(super.asInt16List(offsetInBytes, length));
|
||||
|
||||
Uint32List asUint32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint32ListView(super.asUint32List(offsetInBytes, length));
|
||||
|
||||
Int32List asInt32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32ListView(super.asInt32List(offsetInBytes, length));
|
||||
|
||||
Uint64List asUint64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint64ListView(super.asUint64List(offsetInBytes, length));
|
||||
|
||||
Int64List asInt64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt64ListView(super.asInt64List(offsetInBytes, length));
|
||||
|
||||
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32x4ListView(
|
||||
super.asInt32x4List(offsetInBytes, length));
|
||||
|
||||
Float32List asFloat32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32ListView(
|
||||
super.asFloat32List(offsetInBytes, length));
|
||||
|
||||
Float64List asFloat64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64ListView(
|
||||
super.asFloat64List(offsetInBytes, length));
|
||||
|
||||
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32x4ListView(
|
||||
super.asFloat32x4List(offsetInBytes, length));
|
||||
|
||||
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64x2ListView(
|
||||
super.asFloat64x2List(offsetInBytes, length));
|
||||
|
||||
ByteData asByteData([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableByteDataView(super.asByteData(offsetInBytes, length));
|
||||
}
|
||||
|
||||
@@ -8,351 +8,126 @@ part of dart.typed_data;
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteBufferView.
|
||||
class UnmodifiableByteBufferView implements ByteBuffer {
|
||||
final ByteBuffer _data;
|
||||
|
||||
UnmodifiableByteBufferView(ByteBuffer data) : _data = data;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
Uint8List asUint8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ListView(_data.asUint8List(offsetInBytes, length));
|
||||
|
||||
Int8List asInt8List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt8ListView(_data.asInt8List(offsetInBytes, length));
|
||||
|
||||
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint8ClampedListView(
|
||||
_data.asUint8ClampedList(offsetInBytes, length));
|
||||
|
||||
Uint16List asUint16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint16ListView(_data.asUint16List(offsetInBytes, length));
|
||||
|
||||
Int16List asInt16List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt16ListView(_data.asInt16List(offsetInBytes, length));
|
||||
|
||||
Uint32List asUint32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint32ListView(_data.asUint32List(offsetInBytes, length));
|
||||
|
||||
Int32List asInt32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32ListView(_data.asInt32List(offsetInBytes, length));
|
||||
|
||||
Uint64List asUint64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableUint64ListView(_data.asUint64List(offsetInBytes, length));
|
||||
|
||||
Int64List asInt64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt64ListView(_data.asInt64List(offsetInBytes, length));
|
||||
|
||||
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableInt32x4ListView(
|
||||
_data.asInt32x4List(offsetInBytes, length));
|
||||
|
||||
Float32List asFloat32List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32ListView(
|
||||
_data.asFloat32List(offsetInBytes, length));
|
||||
|
||||
Float64List asFloat64List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64ListView(
|
||||
_data.asFloat64List(offsetInBytes, length));
|
||||
|
||||
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat32x4ListView(
|
||||
_data.asFloat32x4List(offsetInBytes, length));
|
||||
|
||||
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableFloat64x2ListView(
|
||||
_data.asFloat64x2List(offsetInBytes, length));
|
||||
|
||||
ByteData asByteData([int offsetInBytes = 0, int? length]) =>
|
||||
new UnmodifiableByteDataView(_data.asByteData(offsetInBytes, length));
|
||||
abstract class UnmodifiableByteBufferView implements ByteBuffer {
|
||||
external factory UnmodifiableByteBufferView(ByteBuffer data);
|
||||
}
|
||||
|
||||
/// A read-only view of a [ByteData].
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableByteDataView.
|
||||
class UnmodifiableByteDataView implements ByteData {
|
||||
final ByteData _data;
|
||||
|
||||
UnmodifiableByteDataView(ByteData data) : _data = data;
|
||||
|
||||
int getInt8(int byteOffset) => _data.getInt8(byteOffset);
|
||||
|
||||
void setInt8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getUint8(int byteOffset) => _data.getUint8(byteOffset);
|
||||
|
||||
void setUint8(int byteOffset, int value) => _unsupported();
|
||||
|
||||
int getInt16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt16(byteOffset, endian);
|
||||
|
||||
void setInt16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint16(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint16(byteOffset, endian);
|
||||
|
||||
void setUint16(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt32(byteOffset, endian);
|
||||
|
||||
void setInt32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint32(byteOffset, endian);
|
||||
|
||||
void setUint32(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getInt64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getInt64(byteOffset, endian);
|
||||
|
||||
void setInt64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int getUint64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getUint64(byteOffset, endian);
|
||||
|
||||
void setUint64(int byteOffset, int value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat32(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat32(byteOffset, endian);
|
||||
|
||||
void setFloat32(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
double getFloat64(int byteOffset, [Endian endian = Endian.big]) =>
|
||||
_data.getFloat64(byteOffset, endian);
|
||||
|
||||
void setFloat64(int byteOffset, double value, [Endian endian = Endian.big]) =>
|
||||
_unsupported();
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
void _unsupported() {
|
||||
throw new UnsupportedError(
|
||||
"An UnmodifiableByteDataView may not be modified");
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _UnmodifiableListMixin<N, L extends List<N>,
|
||||
TD extends TypedData> {
|
||||
L get _list;
|
||||
TD get _data => (_list as TD);
|
||||
|
||||
int get length => _list.length;
|
||||
|
||||
N operator [](int index) => _list[index];
|
||||
|
||||
int get elementSizeInBytes => _data.elementSizeInBytes;
|
||||
|
||||
int get offsetInBytes => _data.offsetInBytes;
|
||||
|
||||
int get lengthInBytes => _data.lengthInBytes;
|
||||
|
||||
ByteBuffer get buffer => new UnmodifiableByteBufferView(_data.buffer);
|
||||
|
||||
L _createList(int length);
|
||||
|
||||
L sublist(int start, [int? end]) {
|
||||
// NNBD: Spurious error at `end`, `checkValidRange` is legacy.
|
||||
int endIndex = RangeError.checkValidRange(start, end!, length);
|
||||
int sublistLength = endIndex - start;
|
||||
L result = _createList(sublistLength);
|
||||
result.setRange(0, sublistLength, _list, start);
|
||||
return result;
|
||||
}
|
||||
abstract class UnmodifiableByteDataView implements ByteData {
|
||||
external factory UnmodifiableByteDataView(ByteData data);
|
||||
}
|
||||
|
||||
/// View of a [Uint8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ListView.
|
||||
class UnmodifiableUint8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8List, Uint8List>
|
||||
implements Uint8List {
|
||||
final Uint8List _list;
|
||||
UnmodifiableUint8ListView(Uint8List list) : _list = list;
|
||||
|
||||
Uint8List _createList(int length) => Uint8List(length);
|
||||
abstract class UnmodifiableUint8ListView implements Uint8List {
|
||||
external factory UnmodifiableUint8ListView(Uint8List list);
|
||||
}
|
||||
|
||||
/// View of a [Int8List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt8ListView.
|
||||
class UnmodifiableInt8ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int8List, Int8List>
|
||||
implements Int8List {
|
||||
final Int8List _list;
|
||||
UnmodifiableInt8ListView(Int8List list) : _list = list;
|
||||
|
||||
Int8List _createList(int length) => Int8List(length);
|
||||
abstract class UnmodifiableInt8ListView implements Int8List {
|
||||
external factory UnmodifiableInt8ListView(Int8List list);
|
||||
}
|
||||
|
||||
/// View of a [Uint8ClampedList] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint8ClampedListView.
|
||||
class UnmodifiableUint8ClampedListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint8ClampedList, Uint8ClampedList>
|
||||
implements Uint8ClampedList {
|
||||
final Uint8ClampedList _list;
|
||||
UnmodifiableUint8ClampedListView(Uint8ClampedList list) : _list = list;
|
||||
|
||||
Uint8ClampedList _createList(int length) => Uint8ClampedList(length);
|
||||
abstract class UnmodifiableUint8ClampedListView implements Uint8ClampedList {
|
||||
external factory UnmodifiableUint8ClampedListView(Uint8ClampedList list);
|
||||
}
|
||||
|
||||
/// View of a [Uint16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint16ListView.
|
||||
class UnmodifiableUint16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint16List, Uint16List>
|
||||
implements Uint16List {
|
||||
final Uint16List _list;
|
||||
UnmodifiableUint16ListView(Uint16List list) : _list = list;
|
||||
|
||||
Uint16List _createList(int length) => Uint16List(length);
|
||||
abstract class UnmodifiableUint16ListView implements Uint16List {
|
||||
external factory UnmodifiableUint16ListView(Uint16List list);
|
||||
}
|
||||
|
||||
/// View of a [Int16List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt16ListView.
|
||||
class UnmodifiableInt16ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int16List, Int16List>
|
||||
implements Int16List {
|
||||
final Int16List _list;
|
||||
UnmodifiableInt16ListView(Int16List list) : _list = list;
|
||||
|
||||
Int16List _createList(int length) => Int16List(length);
|
||||
abstract class UnmodifiableInt16ListView implements Int16List {
|
||||
external factory UnmodifiableInt16ListView(Int16List list);
|
||||
}
|
||||
|
||||
/// View of a [Uint32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint32ListView.
|
||||
class UnmodifiableUint32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint32List, Uint32List>
|
||||
implements Uint32List {
|
||||
final Uint32List _list;
|
||||
UnmodifiableUint32ListView(Uint32List list) : _list = list;
|
||||
|
||||
Uint32List _createList(int length) => Uint32List(length);
|
||||
abstract class UnmodifiableUint32ListView implements Uint32List {
|
||||
external factory UnmodifiableUint32ListView(Uint32List list);
|
||||
}
|
||||
|
||||
/// View of a [Int32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32ListView.
|
||||
class UnmodifiableInt32ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int32List, Int32List>
|
||||
implements Int32List {
|
||||
final Int32List _list;
|
||||
UnmodifiableInt32ListView(Int32List list) : _list = list;
|
||||
|
||||
Int32List _createList(int length) => Int32List(length);
|
||||
abstract class UnmodifiableInt32ListView implements Int32List {
|
||||
external factory UnmodifiableInt32ListView(Int32List list);
|
||||
}
|
||||
|
||||
/// View of a [Uint64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableUint64ListView.
|
||||
class UnmodifiableUint64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Uint64List, Uint64List>
|
||||
implements Uint64List {
|
||||
final Uint64List _list;
|
||||
UnmodifiableUint64ListView(Uint64List list) : _list = list;
|
||||
|
||||
Uint64List _createList(int length) => Uint64List(length);
|
||||
abstract class UnmodifiableUint64ListView implements Uint64List {
|
||||
external factory UnmodifiableUint64ListView(Uint64List list);
|
||||
}
|
||||
|
||||
/// View of a [Int64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt64ListView.
|
||||
class UnmodifiableInt64ListView extends UnmodifiableListBase<int>
|
||||
with _UnmodifiableListMixin<int, Int64List, Int64List>
|
||||
implements Int64List {
|
||||
final Int64List _list;
|
||||
UnmodifiableInt64ListView(Int64List list) : _list = list;
|
||||
|
||||
Int64List _createList(int length) => Int64List(length);
|
||||
abstract class UnmodifiableInt64ListView implements Int64List {
|
||||
external factory UnmodifiableInt64ListView(Int64List list);
|
||||
}
|
||||
|
||||
/// View of a [Int32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableInt32x4ListView.
|
||||
class UnmodifiableInt32x4ListView extends UnmodifiableListBase<Int32x4>
|
||||
with _UnmodifiableListMixin<Int32x4, Int32x4List, Int32x4List>
|
||||
implements Int32x4List {
|
||||
final Int32x4List _list;
|
||||
UnmodifiableInt32x4ListView(Int32x4List list) : _list = list;
|
||||
|
||||
Int32x4List _createList(int length) => Int32x4List(length);
|
||||
abstract class UnmodifiableInt32x4ListView implements Int32x4List {
|
||||
external factory UnmodifiableInt32x4ListView(Int32x4List list);
|
||||
}
|
||||
|
||||
/// View of a [Float32x4List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32x4ListView.
|
||||
class UnmodifiableFloat32x4ListView extends UnmodifiableListBase<Float32x4>
|
||||
with _UnmodifiableListMixin<Float32x4, Float32x4List, Float32x4List>
|
||||
implements Float32x4List {
|
||||
final Float32x4List _list;
|
||||
UnmodifiableFloat32x4ListView(Float32x4List list) : _list = list;
|
||||
|
||||
Float32x4List _createList(int length) => Float32x4List(length);
|
||||
abstract class UnmodifiableFloat32x4ListView implements Float32x4List {
|
||||
external factory UnmodifiableFloat32x4ListView(Float32x4List list);
|
||||
}
|
||||
|
||||
/// View of a [Float64x2List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64x2ListView.
|
||||
class UnmodifiableFloat64x2ListView extends UnmodifiableListBase<Float64x2>
|
||||
with _UnmodifiableListMixin<Float64x2, Float64x2List, Float64x2List>
|
||||
implements Float64x2List {
|
||||
final Float64x2List _list;
|
||||
UnmodifiableFloat64x2ListView(Float64x2List list) : _list = list;
|
||||
|
||||
Float64x2List _createList(int length) => Float64x2List(length);
|
||||
abstract class UnmodifiableFloat64x2ListView implements Float64x2List {
|
||||
external factory UnmodifiableFloat64x2ListView(Float64x2List list);
|
||||
}
|
||||
|
||||
/// View of a [Float32List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat32ListView.
|
||||
class UnmodifiableFloat32ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float32List, Float32List>
|
||||
implements Float32List {
|
||||
final Float32List _list;
|
||||
UnmodifiableFloat32ListView(Float32List list) : _list = list;
|
||||
|
||||
Float32List _createList(int length) => Float32List(length);
|
||||
abstract class UnmodifiableFloat32ListView implements Float32List {
|
||||
external factory UnmodifiableFloat32ListView(Float32List list);
|
||||
}
|
||||
|
||||
/// View of a [Float64List] that disallows modification.
|
||||
///
|
||||
/// It is a compile-time error for a class to attempt to extend or implement
|
||||
/// UnmodifiableFloat64ListView.
|
||||
class UnmodifiableFloat64ListView extends UnmodifiableListBase<double>
|
||||
with _UnmodifiableListMixin<double, Float64List, Float64List>
|
||||
implements Float64List {
|
||||
final Float64List _list;
|
||||
UnmodifiableFloat64ListView(Float64List list) : _list = list;
|
||||
|
||||
Float64List _createList(int length) => Float64List(length);
|
||||
abstract class UnmodifiableFloat64ListView implements Float64List {
|
||||
external factory UnmodifiableFloat64ListView(Float64List list);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "dart:typed_data";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
const bool supportsInt64 = bool.fromEnvironment("dart.isVM");
|
||||
const int kListSize = 100;
|
||||
const int kLoopSize = 1000;
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint8(Uint8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint8(Uint8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint8() {
|
||||
var internal = new Uint8List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint8(internal);
|
||||
}
|
||||
|
||||
var view = new Uint8List.view(new Uint8List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint8(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint8ListView(new Uint8List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint8(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt8(Int8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt8(Int8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt8() {
|
||||
var internal = new Int8List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt8(internal);
|
||||
}
|
||||
|
||||
var view = new Int8List.view(new Int8List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt8(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt8ListView(new Int8List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt8(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint16(Uint16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint16(Uint16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint16() {
|
||||
var internal = new Uint16List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint16(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint16List.view(new Uint16List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint16(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint16ListView(new Uint16List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint16(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt16(Int16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt16(Int16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt16() {
|
||||
var internal = new Int16List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt16(internal);
|
||||
}
|
||||
|
||||
var view = new Int16List.view(new Int16List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt16(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt16ListView(new Int16List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt16(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint32(Uint32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint32(Uint32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint32() {
|
||||
var internal = new Uint32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint32(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint32List.view(new Uint32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint32(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint32ListView(new Uint32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt32(Int32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt32(Int32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt32() {
|
||||
var internal = new Int32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32(internal);
|
||||
}
|
||||
|
||||
var view = new Int32List.view(new Int32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt32ListView(new Int32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint64(Uint64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint64(Uint64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint64() {
|
||||
var internal = new Uint64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint64(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint64List.view(new Uint64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint64(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint64ListView(new Uint64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt64(Int64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt64(Int64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt64() {
|
||||
var internal = new Int64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt64(internal);
|
||||
}
|
||||
|
||||
var view = new Int64List.view(new Int64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt64(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt64ListView(new Int64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat32(Float32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat32(Float32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
testFloat32() {
|
||||
var internal = new Float32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float32List.view(new Float32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat32ListView(new Float32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat64(Float64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat64(Float64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
testFloat64() {
|
||||
var internal = new Float64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float64List.view(new Float64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat64ListView(new Float64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt32x4(Int32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i].x);
|
||||
Expect.equals(0, list[i].y);
|
||||
Expect.equals(0, list[i].z);
|
||||
Expect.equals(0, list[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt32x4(Int32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Int32x4(1, 2, 3, 4);
|
||||
}
|
||||
}
|
||||
|
||||
testInt32x4() {
|
||||
var internal = new Int32x4List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32x4(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Int32x4List.view(new Int32x4List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32x4(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableInt32x4ListView(new Int32x4List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt32x4(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat32x4(Float32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i].x);
|
||||
Expect.equals(0.0, list[i].y);
|
||||
Expect.equals(0.0, list[i].z);
|
||||
Expect.equals(0.0, list[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat32x4(Float32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Float32x4(1.0, 2.0, 3.0, 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
testFloat32x4() {
|
||||
var internal = new Float32x4List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32x4(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float32x4List.view(new Float32x4List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32x4(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat32x4ListView(new Float32x4List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat32x4(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat64x2(Float64x2List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i].x);
|
||||
Expect.equals(0.0, list[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat64x2(Float64x2List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Float64x2(1.0, 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
testFloat64x2() {
|
||||
var internal = new Float64x2List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64x2(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float64x2List.view(new Float64x2List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64x2(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat64x2ListView(new Float64x2List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat64x2(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readByteData(ByteData data) {
|
||||
for (int i = 0; i < data.lengthInBytes; i++) {
|
||||
Expect.equals(0, data.getUint8(i));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeByteData(ByteData data) {
|
||||
for (int i = 0; i < data.lengthInBytes; i++) {
|
||||
data.setUint8(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
testByteData() {
|
||||
var internal = new ByteData(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeByteData(internal);
|
||||
}
|
||||
|
||||
var view = new ByteData.view(new ByteData(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeByteData(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableByteDataView(new ByteData(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeByteData(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
testUint8();
|
||||
testInt8();
|
||||
testUint16();
|
||||
testInt16();
|
||||
testUint32();
|
||||
testInt32();
|
||||
if (supportsInt64) {
|
||||
testUint64();
|
||||
testInt64();
|
||||
}
|
||||
testFloat32();
|
||||
testFloat64();
|
||||
testInt32x4();
|
||||
testFloat32x4();
|
||||
testFloat64x2();
|
||||
testByteData();
|
||||
}
|
||||
@@ -36,11 +36,19 @@ checkUnmodifiable(List<int> list) {
|
||||
Expect.throwsUnsupportedError(() => list.setAll(0, [one]));
|
||||
}
|
||||
|
||||
checkIndirectUnmodifiable(TypedData data) {
|
||||
var newView1 = data.buffer.asUint8List();
|
||||
Expect.throwsUnsupportedError(() => newView1[0] = 1);
|
||||
var newView2 = Uint8List.view(data.buffer);
|
||||
Expect.throwsUnsupportedError(() => newView2[0] = 1);
|
||||
}
|
||||
|
||||
int8ListTest() {
|
||||
Int8List i8l = new Int8List.fromList(intList);
|
||||
UnmodifiableInt8ListView list = new UnmodifiableInt8ListView(i8l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint8ListTest() {
|
||||
@@ -48,6 +56,7 @@ uint8ListTest() {
|
||||
UnmodifiableUint8ListView list = new UnmodifiableUint8ListView(u8l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int16ListTest() {
|
||||
@@ -55,6 +64,7 @@ int16ListTest() {
|
||||
UnmodifiableInt16ListView list = new UnmodifiableInt16ListView(i16l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint16ListTest() {
|
||||
@@ -62,6 +72,7 @@ uint16ListTest() {
|
||||
UnmodifiableUint16ListView list = new UnmodifiableUint16ListView(u16l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int32ListTest() {
|
||||
@@ -69,6 +80,7 @@ int32ListTest() {
|
||||
UnmodifiableInt32ListView list = new UnmodifiableInt32ListView(i32l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint32ListTest() {
|
||||
@@ -76,6 +88,7 @@ uint32ListTest() {
|
||||
UnmodifiableUint32ListView list = new UnmodifiableUint32ListView(u32l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int64ListTest() {
|
||||
@@ -83,6 +96,7 @@ int64ListTest() {
|
||||
UnmodifiableInt64ListView list = new UnmodifiableInt64ListView(i64l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint64ListTest() {
|
||||
@@ -90,6 +104,7 @@ uint64ListTest() {
|
||||
UnmodifiableUint64ListView list = new UnmodifiableUint64ListView(u64l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
List<double> doubleList = <double>[1.0, 2.0, 3.0, 4.0, 5.0];
|
||||
@@ -126,6 +141,7 @@ float32ListTest() {
|
||||
UnmodifiableFloat32ListView list = new UnmodifiableFloat32ListView(f32l);
|
||||
checkDoubleReadable(list);
|
||||
checkDoubleUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
float64ListTest() {
|
||||
@@ -133,6 +149,7 @@ float64ListTest() {
|
||||
UnmodifiableFloat64ListView list = new UnmodifiableFloat64ListView(f64l);
|
||||
checkDoubleReadable(list);
|
||||
checkDoubleUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
byteDataTest() {
|
||||
@@ -150,6 +167,8 @@ byteDataTest() {
|
||||
Expect.throwsUnsupportedError(() => ubdv.setUint64(0, 0));
|
||||
Expect.throwsUnsupportedError(() => ubdv.setFloat32(0, 0.0));
|
||||
Expect.throwsUnsupportedError(() => ubdv.setFloat64(0, 0.0));
|
||||
|
||||
checkIndirectUnmodifiable(ubdv);
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// The view implementation requires flattening views of views.
|
||||
|
||||
import "dart:typed_data";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
const int kListSize = 100;
|
||||
const int kLoopSize = 1000;
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readArray(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readView(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readUnmodifiableView(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readPolymorphic(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readDynamic(dynamic list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
var array = new Uint8List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readArray(array);
|
||||
readPolymorphic(array);
|
||||
readDynamic(array);
|
||||
}
|
||||
|
||||
var view = new Uint8List.view(array.buffer);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readView(view);
|
||||
readPolymorphic(view);
|
||||
readDynamic(view);
|
||||
}
|
||||
|
||||
var unmodifiableView1 = new UnmodifiableUint8ListView(array);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUnmodifiableView(unmodifiableView1);
|
||||
readPolymorphic(unmodifiableView1);
|
||||
readDynamic(unmodifiableView1);
|
||||
}
|
||||
|
||||
var unmodifiableView2 = new UnmodifiableUint8ListView(view);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUnmodifiableView(unmodifiableView2);
|
||||
readPolymorphic(unmodifiableView2);
|
||||
readDynamic(unmodifiableView2);
|
||||
}
|
||||
|
||||
var viewOfView1 = new Uint8List.view(view.buffer);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readView(viewOfView1);
|
||||
readPolymorphic(viewOfView1);
|
||||
readDynamic(viewOfView1);
|
||||
}
|
||||
|
||||
var viewOfView2 = new Uint8List.view(unmodifiableView1.buffer);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readView(viewOfView2);
|
||||
readPolymorphic(viewOfView2);
|
||||
readDynamic(viewOfView2);
|
||||
}
|
||||
|
||||
var viewOfView3 = new Uint8List.view(unmodifiableView2.buffer);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readView(viewOfView3);
|
||||
readDynamic(viewOfView3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,611 @@
|
||||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import "dart:typed_data";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
const bool supportsInt64 = bool.fromEnvironment("dart.isVM");
|
||||
const int kListSize = 100;
|
||||
const int kLoopSize = 1000;
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint8(Uint8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint8(Uint8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint8() {
|
||||
var internal = new Uint8List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint8(internal);
|
||||
}
|
||||
|
||||
var view = new Uint8List.view(new Uint8List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint8(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint8ListView(new Uint8List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint8(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint8(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt8(Int8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt8(Int8List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt8() {
|
||||
var internal = new Int8List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt8(internal);
|
||||
}
|
||||
|
||||
var view = new Int8List.view(new Int8List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt8(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt8ListView(new Int8List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt8(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt8(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint16(Uint16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint16(Uint16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint16() {
|
||||
var internal = new Uint16List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint16(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint16List.view(new Uint16List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint16(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint16ListView(new Uint16List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint16(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint16(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt16(Int16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt16(Int16List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt16() {
|
||||
var internal = new Int16List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt16(internal);
|
||||
}
|
||||
|
||||
var view = new Int16List.view(new Int16List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt16(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt16ListView(new Int16List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt16(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt16(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint32(Uint32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint32(Uint32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint32() {
|
||||
var internal = new Uint32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint32(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint32List.view(new Uint32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint32(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint32ListView(new Uint32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt32(Int32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt32(Int32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt32() {
|
||||
var internal = new Int32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32(internal);
|
||||
}
|
||||
|
||||
var view = new Int32List.view(new Int32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt32ListView(new Int32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readUint64(Uint64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeUint64(Uint64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testUint64() {
|
||||
var internal = new Uint64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint64(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Uint64List.view(new Uint64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeUint64(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableUint64ListView(new Uint64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readUint64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeUint64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt64(Int64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt64(Int64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
testInt64() {
|
||||
var internal = new Int64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt64(internal);
|
||||
}
|
||||
|
||||
var view = new Int64List.view(new Int64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt64(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableInt64ListView(new Int64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat32(Float32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat32(Float32List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
testFloat32() {
|
||||
var internal = new Float32List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float32List.view(new Float32List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat32ListView(new Float32List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat32(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat64(Float64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat64(Float64List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
testFloat64() {
|
||||
var internal = new Float64List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float64List.view(new Float64List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat64ListView(new Float64List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat64(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readInt32x4(Int32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i].x);
|
||||
Expect.equals(0, list[i].y);
|
||||
Expect.equals(0, list[i].z);
|
||||
Expect.equals(0, list[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeInt32x4(Int32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Int32x4(1, 2, 3, 4);
|
||||
}
|
||||
}
|
||||
|
||||
testInt32x4() {
|
||||
var internal = new Int32x4List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32x4(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Int32x4List.view(new Int32x4List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeInt32x4(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableInt32x4ListView(new Int32x4List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readInt32x4(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeInt32x4(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat32x4(Float32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i].x);
|
||||
Expect.equals(0.0, list[i].y);
|
||||
Expect.equals(0.0, list[i].z);
|
||||
Expect.equals(0.0, list[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat32x4(Float32x4List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Float32x4(1.0, 2.0, 3.0, 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
testFloat32x4() {
|
||||
var internal = new Float32x4List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32x4(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float32x4List.view(new Float32x4List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat32x4(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat32x4ListView(new Float32x4List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat32x4(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat32x4(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readFloat64x2(Float64x2List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Expect.equals(0.0, list[i].x);
|
||||
Expect.equals(0.0, list[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeFloat64x2(Float64x2List list) {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = Float64x2(1.0, 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
testFloat64x2() {
|
||||
var internal = new Float64x2List(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64x2(internal);
|
||||
}
|
||||
|
||||
var view =
|
||||
new Float64x2List.view(new Float64x2List(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeFloat64x2(view);
|
||||
}
|
||||
|
||||
var unmodifiable =
|
||||
new UnmodifiableFloat64x2ListView(new Float64x2List(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readFloat64x2(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeFloat64x2(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
readByteData(ByteData data) {
|
||||
for (int i = 0; i < data.lengthInBytes; i++) {
|
||||
Expect.equals(0, data.getUint8(i));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
writeByteData(ByteData data) {
|
||||
for (int i = 0; i < data.lengthInBytes; i++) {
|
||||
data.setUint8(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
testByteData() {
|
||||
var internal = new ByteData(kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(internal);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeByteData(internal);
|
||||
}
|
||||
|
||||
var view = new ByteData.view(new ByteData(kListSize).buffer, 0, kListSize);
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(view);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
writeByteData(view);
|
||||
}
|
||||
|
||||
var unmodifiable = new UnmodifiableByteDataView(new ByteData(kListSize));
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
readByteData(unmodifiable);
|
||||
}
|
||||
for (var i = 0; i < kLoopSize; i++) {
|
||||
Expect.throwsUnsupportedError(() => writeByteData(unmodifiable));
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
testUint8();
|
||||
testInt8();
|
||||
testUint16();
|
||||
testInt16();
|
||||
testUint32();
|
||||
testInt32();
|
||||
if (supportsInt64) {
|
||||
testUint64();
|
||||
testInt64();
|
||||
}
|
||||
testFloat32();
|
||||
testFloat64();
|
||||
testInt32x4();
|
||||
testFloat32x4();
|
||||
testFloat64x2();
|
||||
testByteData();
|
||||
}
|
||||
@@ -38,11 +38,19 @@ checkUnmodifiable(List<int> list) {
|
||||
Expect.throwsUnsupportedError(() => list.setAll(0, [one]));
|
||||
}
|
||||
|
||||
checkIndirectUnmodifiable(TypedData data) {
|
||||
var newView1 = data.buffer.asUint8List();
|
||||
Expect.throwsUnsupportedError(() => newView1[0] = 1);
|
||||
var newView2 = Uint8List.view(data.buffer);
|
||||
Expect.throwsUnsupportedError(() => newView2[0] = 1);
|
||||
}
|
||||
|
||||
int8ListTest() {
|
||||
Int8List i8l = new Int8List.fromList(intList);
|
||||
UnmodifiableInt8ListView list = new UnmodifiableInt8ListView(i8l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint8ListTest() {
|
||||
@@ -50,6 +58,7 @@ uint8ListTest() {
|
||||
UnmodifiableUint8ListView list = new UnmodifiableUint8ListView(u8l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int16ListTest() {
|
||||
@@ -57,6 +66,7 @@ int16ListTest() {
|
||||
UnmodifiableInt16ListView list = new UnmodifiableInt16ListView(i16l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint16ListTest() {
|
||||
@@ -64,6 +74,7 @@ uint16ListTest() {
|
||||
UnmodifiableUint16ListView list = new UnmodifiableUint16ListView(u16l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int32ListTest() {
|
||||
@@ -71,6 +82,7 @@ int32ListTest() {
|
||||
UnmodifiableInt32ListView list = new UnmodifiableInt32ListView(i32l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint32ListTest() {
|
||||
@@ -78,6 +90,7 @@ uint32ListTest() {
|
||||
UnmodifiableUint32ListView list = new UnmodifiableUint32ListView(u32l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
int64ListTest() {
|
||||
@@ -85,6 +98,7 @@ int64ListTest() {
|
||||
UnmodifiableInt64ListView list = new UnmodifiableInt64ListView(i64l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
uint64ListTest() {
|
||||
@@ -92,6 +106,7 @@ uint64ListTest() {
|
||||
UnmodifiableUint64ListView list = new UnmodifiableUint64ListView(u64l);
|
||||
checkReadable(list);
|
||||
checkUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
List<double> doubleList = <double>[1.0, 2.0, 3.0, 4.0, 5.0];
|
||||
@@ -128,6 +143,7 @@ float32ListTest() {
|
||||
UnmodifiableFloat32ListView list = new UnmodifiableFloat32ListView(f32l);
|
||||
checkDoubleReadable(list);
|
||||
checkDoubleUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
float64ListTest() {
|
||||
@@ -135,6 +151,7 @@ float64ListTest() {
|
||||
UnmodifiableFloat64ListView list = new UnmodifiableFloat64ListView(f64l);
|
||||
checkDoubleReadable(list);
|
||||
checkDoubleUnmodifiable(list);
|
||||
checkIndirectUnmodifiable(list);
|
||||
}
|
||||
|
||||
byteDataTest() {
|
||||
@@ -152,6 +169,8 @@ byteDataTest() {
|
||||
Expect.throwsUnsupportedError(() => ubdv.setUint64(0, 0));
|
||||
Expect.throwsUnsupportedError(() => ubdv.setFloat32(0, 0.0));
|
||||
Expect.throwsUnsupportedError(() => ubdv.setFloat64(0, 0.0));
|
||||
|
||||
checkIndirectUnmodifiable(ubdv);
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// The view implementation requires flattening views of views.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import "dart:typed_data";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readArray(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readView(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readUnmodifiableView(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readPolymorphic(Uint8List list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@pragma("vm:never-inline")
|
||||
void readDynamic(dynamic list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
Expect.equals(0, list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
var array = new Uint8List(100);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readArray(array);
|
||||
readPolymorphic(array);
|
||||
readDynamic(array);
|
||||
}
|
||||
|
||||
var view = new Uint8List.view(array.buffer);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readView(view);
|
||||
readPolymorphic(view);
|
||||
readDynamic(view);
|
||||
}
|
||||
|
||||
var unmodifiableView1 = new UnmodifiableUint8ListView(array);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readUnmodifiableView(unmodifiableView1);
|
||||
readPolymorphic(unmodifiableView1);
|
||||
readDynamic(unmodifiableView1);
|
||||
}
|
||||
|
||||
var unmodifiableView2 = new UnmodifiableUint8ListView(view);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readUnmodifiableView(unmodifiableView2);
|
||||
readPolymorphic(unmodifiableView2);
|
||||
readDynamic(unmodifiableView2);
|
||||
}
|
||||
|
||||
var viewOfView1 = new Uint8List.view(view.buffer);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readView(viewOfView1);
|
||||
readPolymorphic(viewOfView1);
|
||||
readDynamic(viewOfView1);
|
||||
}
|
||||
|
||||
var viewOfView2 = new Uint8List.view(unmodifiableView1.buffer);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readView(viewOfView2);
|
||||
readPolymorphic(viewOfView2);
|
||||
readDynamic(viewOfView2);
|
||||
}
|
||||
|
||||
var viewOfView3 = new Uint8List.view(unmodifiableView2.buffer);
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
readView(viewOfView3);
|
||||
readDynamic(viewOfView3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user