Dart - make ascii optimization optional in StringReader, same as in writeString() (#6758)
This commit is contained in:
parent
c871df7702
commit
5235133f32
|
@ -1033,20 +1033,21 @@ abstract class Reader<T> {
|
|||
|
||||
/// The reader of string values.
|
||||
class StringReader extends Reader<String> {
|
||||
const StringReader() : super();
|
||||
final bool asciiOptimization;
|
||||
const StringReader({this.asciiOptimization = false}) : super();
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
int get size => 4;
|
||||
int get size => _sizeofUint32;
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
String read(BufferContext bc, int offset) {
|
||||
int strOffset = bc.derefObject(offset);
|
||||
int length = bc._getUint32(strOffset);
|
||||
Uint8List bytes = bc._asUint8List(strOffset + 4, length);
|
||||
if (_isLatin(bytes)) {
|
||||
return new String.fromCharCodes(bytes);
|
||||
Uint8List bytes = bc._asUint8List(strOffset + _sizeofUint32, length);
|
||||
if (asciiOptimization && _isLatin(bytes)) {
|
||||
return String.fromCharCodes(bytes);
|
||||
}
|
||||
return utf8.decode(bytes);
|
||||
}
|
||||
|
|
|
@ -379,7 +379,7 @@ class BuilderTest {
|
|||
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||
latinString);
|
||||
expect(
|
||||
const StringReader()
|
||||
const StringReader(asciiOptimization: true)
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||
unicodeString);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue