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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.summary.flat_buffers; 5 library analyzer.src.summary.flat_buffers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:math'; 9 import 'dart:math';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 class StringReader extends Reader<String> { 660 class StringReader extends Reader<String> {
661 const StringReader() : super(); 661 const StringReader() : super();
662 662
663 @override 663 @override
664 int get size => 4; 664 int get size => 4;
665 665
666 @override 666 @override
667 String read(BufferPointer ref) { 667 String read(BufferPointer ref) {
668 BufferPointer object = ref.derefObject(); 668 BufferPointer object = ref.derefObject();
669 int length = object._getUint32(); 669 int length = object._getUint32();
670 return UTF8 670 Uint8List bytes = ref._buffer.buffer.asUint8List(object._offset + 4, length) ;
671 .decode(ref._buffer.buffer.asUint8List(object._offset + 4, length)); 671 if (_isLatin(bytes)) {
672 return new String.fromCharCodes(bytes);
673 }
674 return UTF8.decode(bytes);
675 }
676
677 static bool _isLatin(Uint8List bytes) {
678 int length = bytes.length;
679 for (int i = 0; i < length; i++) {
680 if (bytes[i] > 127) {
681 return false;
682 }
683 }
684 return true;
672 } 685 }
673 } 686 }
674 687
675 /** 688 /**
676 * An abstract reader for tables. 689 * An abstract reader for tables.
677 */ 690 */
678 abstract class TableReader<T> extends Reader<T> { 691 abstract class TableReader<T> extends Reader<T> {
679 const TableReader(); 692 const TableReader();
680 693
681 @override 694 @override
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // Table size. 948 // Table size.
936 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); 949 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN);
937 bufOffset += 2; 950 bufOffset += 2;
938 // Field offsets. 951 // Field offsets.
939 for (int fieldOffset in fieldOffsets) { 952 for (int fieldOffset in fieldOffsets) {
940 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); 953 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN);
941 bufOffset += 2; 954 bufOffset += 2;
942 } 955 }
943 } 956 }
944 } 957 }
OLDNEW
« 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