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

Side by Side Diff: runtime/lib/convert_patch.dart

Issue 368483004: Avoid unnecessary copying when parsing doubles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also use the native parse directly in JSON parsing. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/double.cc » ('j') | runtime/lib/double.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import "dart:typed_data"; 5 import "dart:typed_data";
6 6
7 // JSON conversion. 7 // JSON conversion.
8 8
9 patch _parseJson(String json, reviver(var key, var value)) { 9 patch _parseJson(String json, reviver(var key, var value)) {
10 _BuildJsonListener listener; 10 _BuildJsonListener listener;
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 position++; 551 position++;
552 if (position == length) break parsing; 552 if (position == length) break parsing;
553 char = source.codeUnitAt(position); 553 char = source.codeUnitAt(position);
554 } while (CHAR_0 <= char && char <= CHAR_9); 554 } while (CHAR_0 <= char && char <= CHAR_9);
555 } 555 }
556 } 556 }
557 if (!isDouble) { 557 if (!isDouble) {
558 listener.handleNumber(intSign * intValue); 558 listener.handleNumber(intSign * intValue);
559 return position; 559 return position;
560 } 560 }
561 // Consider whether we can have an int/double.parse that works on part of
562 // a string, to avoid creating the substring.
563 String literal = source.substring(start, position);
564 // This correctly creates -0.0 for doubles. 561 // This correctly creates -0.0 for doubles.
565 listener.handleNumber(double.parse(literal)); 562 listener.handleNumber(_parseDouble(source, start, position));
566 return position; 563 return position;
567 } 564 }
568 565
566 static double _parseDouble(String str,
567 int start, int end) native "Double_parse";
568
569 void fail(int position, [String message]) { 569 void fail(int position, [String message]) {
570 if (message == null) message = "Unexpected character"; 570 if (message == null) message = "Unexpected character";
571 listener.fail(source, position, message); 571 listener.fail(source, position, message);
572 // If the listener didn't throw, do it here. 572 // If the listener didn't throw, do it here.
573 String slice; 573 String slice;
574 int sliceEnd = position + 20; 574 int sliceEnd = position + 20;
575 if (sliceEnd > source.length) { 575 if (sliceEnd > source.length) {
576 slice = "'${source.substring(position)}'"; 576 slice = "'${source.substring(position)}'";
577 } else { 577 } else {
578 slice = "'${source.substring(position, sliceEnd)}...'"; 578 slice = "'${source.substring(position, sliceEnd)}...'";
579 } 579 }
580 throw new FormatException("Unexpected character at $position: $slice"); 580 throw new FormatException("Unexpected character at $position: $slice");
581 } 581 }
582 } 582 }
583 583
584 // UTF-8 conversion. 584 // UTF-8 conversion.
585 585
586 patch class _Utf8Encoder { 586 patch class _Utf8Encoder {
587 /* patch */ static List<int> _createBuffer(int size) => new Uint8List(size); 587 /* patch */ static List<int> _createBuffer(int size) => new Uint8List(size);
588 } 588 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/double.cc » ('j') | runtime/lib/double.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698