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