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

Unified Diff: runtime/lib/string_patch.dart

Issue 212423003: Optimize String.fromCharCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_patch.dart
diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
index 717e49db71984f56878bbfcf0cde617c7efb3be5..299ad6a8bda0a86cab119252297427f6caaf3a2c 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -7,6 +7,24 @@ patch class String {
return _StringBase.createFromCharCodes(charCodes);
}
+ /* patch */ factory String.fromCharCode(int charCode) {
+ if (charCode >= 0) {
+ if (charCode <= 0xff) {
+ return _OneByteString._allocate(1).._setAt(0, charCode);
+ }
+ if (charCode <= 0xffff) {
Lasse Reichstein Nielsen 2014/03/26 09:59:59 What should I do to get _TwoByteString._allocate t
Søren Gjesse 2014/03/26 10:10:33 I think you can just add to to string.cc and send
+ return _StringBase._createFromCodePoints([charCode]);
+ }
+ if (charCode <= 0x10ffff) {
+ var low = 0xDC00 | (charCode & 0x3ff);
+ int bits = charCode - 0x10000;
+ var high = 0xD800 | (bits >> 10);
+ return _StringBase._createFromCodePoints([high, low]);
+ }
+ }
+ throw new RangeError.range(charCode, 0, 0x10ffff);
+ }
+
/* patch */ const factory String.fromEnvironment(String name,
{String defaultValue})
native "String_fromEnvironment";
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698