mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:59:47 +00:00
[vm] Extend string optimizations to UnmodifiableUint8List.
The language now prevents third-party implementations of Uint8List, so a regular `is` check guarantees a VM implementation. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/50194 Change-Id: I8b414e9609fe2f682dfbb16495a9efb99ecdd11c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264080 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
8436076fe4
commit
11bf5d8632
|
@ -4830,17 +4830,15 @@ bool Class::InjectCIDFields() const {
|
|||
#define ADD_SET_FIELD(clazz) {"cid" #clazz, k##clazz##Cid},
|
||||
CLASS_LIST_WITH_NULL(ADD_SET_FIELD)
|
||||
#undef ADD_SET_FIELD
|
||||
#define ADD_SET_FIELD(clazz) {"cid" #clazz "View", kTypedData##clazz##ViewCid},
|
||||
#undef CLASS_LIST_WITH_NULL
|
||||
#define ADD_SET_FIELD(clazz) \
|
||||
{"cid" #clazz, kTypedData##clazz##Cid}, \
|
||||
{"cid" #clazz "View", kTypedData##clazz##ViewCid}, \
|
||||
{"cidExternal" #clazz, kExternalTypedData##clazz##Cid}, \
|
||||
{"cidUnmodifiable" #clazz "View", \
|
||||
kUnmodifiableTypedData##clazz##ViewCid},
|
||||
CLASS_LIST_TYPED_DATA(ADD_SET_FIELD)
|
||||
#undef ADD_SET_FIELD
|
||||
#define ADD_SET_FIELD(clazz) {"cid" #clazz, kTypedData##clazz##Cid},
|
||||
CLASS_LIST_TYPED_DATA(ADD_SET_FIELD)
|
||||
#undef ADD_SET_FIELD
|
||||
#define ADD_SET_FIELD(clazz) \
|
||||
{"cidExternal" #clazz, kExternalTypedData##clazz##Cid},
|
||||
CLASS_LIST_TYPED_DATA(ADD_SET_FIELD)
|
||||
#undef ADD_SET_FIELD
|
||||
#undef CLASS_LIST_WITH_NULL
|
||||
// Used in const hashing to determine whether we're dealing with a
|
||||
// user-defined const. See lib/_internal/vm/lib/compact_hash.dart.
|
||||
{"numPredefinedCids", kNumPredefinedCids},
|
||||
|
|
|
@ -219,11 +219,6 @@ class _RandomAccessFileOps {
|
|||
}
|
||||
}
|
||||
|
||||
@patch
|
||||
bool _isDirectIOCapableTypedList(List<int> buffer) {
|
||||
throw UnsupportedError("_isDirectIOCapableTypedList");
|
||||
}
|
||||
|
||||
@patch
|
||||
class _IOCrypto {
|
||||
@patch
|
||||
|
|
|
@ -218,11 +218,6 @@ class _RandomAccessFileOps {
|
|||
}
|
||||
}
|
||||
|
||||
@patch
|
||||
bool _isDirectIOCapableTypedList(List<int> buffer) {
|
||||
throw UnsupportedError("_isDirectIOCapableTypedList");
|
||||
}
|
||||
|
||||
@patch
|
||||
class _IOCrypto {
|
||||
@patch
|
||||
|
|
|
@ -50,19 +50,6 @@ part "stdio_patch.dart";
|
|||
part "secure_socket_patch.dart";
|
||||
part "sync_socket_patch.dart";
|
||||
|
||||
@patch
|
||||
bool _isDirectIOCapableTypedList(List<int> buffer) {
|
||||
int classID = ClassID.getID(buffer);
|
||||
return classID == ClassID.cidExternalInt8Array ||
|
||||
classID == ClassID.cidExternalUint8Array ||
|
||||
classID == ClassID.cidExternalUint8ClampedArray ||
|
||||
classID == ClassID.cidInt8Array ||
|
||||
classID == ClassID.cidInt8ArrayView ||
|
||||
classID == ClassID.cidUint8Array ||
|
||||
classID == ClassID.cidUint8ArrayView ||
|
||||
classID == ClassID.cidUint8ClampedArray;
|
||||
}
|
||||
|
||||
@patch
|
||||
class OSError {
|
||||
@patch
|
||||
|
|
|
@ -235,10 +235,7 @@ abstract class _StringBase implements String {
|
|||
var s = _OneByteString._allocate(len);
|
||||
|
||||
// Special case for native Uint8 typed arrays.
|
||||
final int cid = ClassID.getID(charCodes);
|
||||
if (cid == ClassID.cidUint8ArrayView ||
|
||||
cid == ClassID.cidUint8Array ||
|
||||
cid == ClassID.cidExternalUint8Array) {
|
||||
if (charCodes is Uint8List) {
|
||||
Uint8List bytes = unsafeCast<Uint8List>(charCodes);
|
||||
copyRangeFromUint8ListToOneByteString(bytes, s, start, 0, len);
|
||||
return s;
|
||||
|
|
|
@ -1686,14 +1686,6 @@ class _Utf8Decoder {
|
|||
return size;
|
||||
}
|
||||
|
||||
@pragma("vm:prefer-inline")
|
||||
static bool _isNativeUint8List(List<int> array) {
|
||||
final int cid = ClassID.getID(array);
|
||||
return cid == ClassID.cidUint8ArrayView ||
|
||||
cid == ClassID.cidUint8Array ||
|
||||
cid == ClassID.cidExternalUint8Array;
|
||||
}
|
||||
|
||||
// The VM decoder handles BOM explicitly instead of via the state machine.
|
||||
@patch
|
||||
_Utf8Decoder(this.allowMalformed) : _state = initial;
|
||||
|
@ -1705,7 +1697,7 @@ class _Utf8Decoder {
|
|||
// Have bytes as Uint8List.
|
||||
Uint8List bytes;
|
||||
int errorOffset;
|
||||
if (_isNativeUint8List(codeUnits)) {
|
||||
if (codeUnits is Uint8List) {
|
||||
bytes = unsafeCast<Uint8List>(codeUnits);
|
||||
errorOffset = 0;
|
||||
} else {
|
||||
|
@ -1769,7 +1761,7 @@ class _Utf8Decoder {
|
|||
// Have bytes as Uint8List.
|
||||
Uint8List bytes;
|
||||
int errorOffset;
|
||||
if (_isNativeUint8List(codeUnits)) {
|
||||
if (codeUnits is Uint8List) {
|
||||
bytes = unsafeCast<Uint8List>(codeUnits);
|
||||
errorOffset = 0;
|
||||
} else {
|
||||
|
|
|
@ -218,11 +218,6 @@ class _RandomAccessFileOps {
|
|||
}
|
||||
}
|
||||
|
||||
@patch
|
||||
bool _isDirectIOCapableTypedList(List<int> buffer) {
|
||||
throw UnsupportedError("_isDirectIOCapableTypedList");
|
||||
}
|
||||
|
||||
@patch
|
||||
class _IOCrypto {
|
||||
@patch
|
||||
|
|
|
@ -88,7 +88,7 @@ class _BufferAndStart {
|
|||
// benefit that it is faster to access from the C code as well.
|
||||
_BufferAndStart _ensureFastAndSerializableByteData(
|
||||
List<int> buffer, int start, int end) {
|
||||
if (_isDirectIOCapableTypedList(buffer)) {
|
||||
if (buffer is Uint8List) {
|
||||
return new _BufferAndStart(buffer, start);
|
||||
}
|
||||
int length = end - start;
|
||||
|
@ -97,9 +97,6 @@ _BufferAndStart _ensureFastAndSerializableByteData(
|
|||
return new _BufferAndStart(newBuffer, 0);
|
||||
}
|
||||
|
||||
// The VM will use ClassID to check whether buffer is Uint8List or Int8List.
|
||||
external bool _isDirectIOCapableTypedList(List<int> buffer);
|
||||
|
||||
class _IOCrypto {
|
||||
external static Uint8List getRandomBytes(int count);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue