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

Side by Side Diff: src/objects.cc

Issue 2018963002: [builtins] Migrate String.prototype.trim/trimLeft/trimRight to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 9964 matching lines...) Expand 10 before | Expand all | Expand 10 after
9975 if (IsEmpty()) return other->IsEmpty(); 9975 if (IsEmpty()) return other->IsEmpty();
9976 if (other->IsEmpty()) return false; 9976 if (other->IsEmpty()) return false;
9977 if (length() != other->length()) return false; 9977 if (length() != other->length()) return false;
9978 for (int i = 0; i < length(); ++i) { 9978 for (int i = 0; i < length(); ++i) {
9979 if (get(i) != other->get(i)) return false; 9979 if (get(i) != other->get(i)) return false;
9980 } 9980 }
9981 return true; 9981 return true;
9982 } 9982 }
9983 #endif 9983 #endif
9984 9984
9985 // static
9986 Handle<String> String::Trim(Handle<String> string, TrimMode mode) {
9987 Isolate* const isolate = string->GetIsolate();
9988
9989 // Flatten the input {string}.
Franzi 2016/05/27 14:20:08 Do we need this comment?
Benedikt Meurer 2016/05/27 17:20:58 Done.
9990 string = String::Flatten(string);
9991 int const length = string->length();
9992
9993 // Perform left trimming if requested.
9994 int left = 0;
9995 UnicodeCache* unicode_cache = isolate->unicode_cache();
9996 if (mode & kTrimLeft) {
Franzi 2016/05/27 14:20:08 For readability, I would prefer if (mode == kTrim
Benedikt Meurer 2016/05/27 17:20:58 Good suggestion, thanks. Did that.
9997 while (left < length &&
9998 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(left))) {
9999 left++;
10000 }
10001 }
10002
10003 // Perform right trimming if requested.
10004 int right = length;
10005 if (mode & kTrimRight) {
10006 while (
10007 right > left &&
10008 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) {
10009 right--;
10010 }
10011 }
10012
10013 return isolate->factory()->NewSubString(string, left, right);
10014 }
9985 10015
9986 bool String::LooksValid() { 10016 bool String::LooksValid() {
9987 if (!GetIsolate()->heap()->Contains(this)) return false; 10017 if (!GetIsolate()->heap()->Contains(this)) return false;
9988 return true; 10018 return true;
9989 } 10019 }
9990 10020
9991 10021
9992 // static 10022 // static
9993 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) { 10023 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) {
9994 if (name->IsString()) return Handle<String>::cast(name); 10024 if (name->IsString()) return Handle<String>::cast(name);
(...skipping 8530 matching lines...) Expand 10 before | Expand all | Expand 10 after
18525 if (cell->value() != *new_value) { 18555 if (cell->value() != *new_value) {
18526 cell->set_value(*new_value); 18556 cell->set_value(*new_value);
18527 Isolate* isolate = cell->GetIsolate(); 18557 Isolate* isolate = cell->GetIsolate();
18528 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18558 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18529 isolate, DependentCode::kPropertyCellChangedGroup); 18559 isolate, DependentCode::kPropertyCellChangedGroup);
18530 } 18560 }
18531 } 18561 }
18532 18562
18533 } // namespace internal 18563 } // namespace internal
18534 } // namespace v8 18564 } // namespace v8
OLDNEW
« src/builtins.cc ('K') | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698