Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1999433002: Use String.fromCharCodes() instead of UTF8.decode() for Latin strings. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/flat_buffers.dart
diff --git a/pkg/analyzer/lib/src/summary/flat_buffers.dart b/pkg/analyzer/lib/src/summary/flat_buffers.dart
index d573693d40d08b770d5395d5118e523a7ae766d3..ceb950d71d6e91c089217139f2596715e7992202 100644
--- a/pkg/analyzer/lib/src/summary/flat_buffers.dart
+++ b/pkg/analyzer/lib/src/summary/flat_buffers.dart
@@ -667,8 +667,21 @@ class StringReader extends Reader<String> {
String read(BufferPointer ref) {
BufferPointer object = ref.derefObject();
int length = object._getUint32();
- return UTF8
- .decode(ref._buffer.buffer.asUint8List(object._offset + 4, length));
+ Uint8List bytes = ref._buffer.buffer.asUint8List(object._offset + 4, length);
+ if (_isLatin(bytes)) {
+ return new String.fromCharCodes(bytes);
+ }
+ return UTF8.decode(bytes);
+ }
+
+ static bool _isLatin(Uint8List bytes) {
+ int length = bytes.length;
+ for (int i = 0; i < length; i++) {
+ if (bytes[i] > 127) {
+ return false;
+ }
+ }
+ return true;
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698