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

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: Address Franziskas comments. 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
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('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 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 string = String::Flatten(string);
9989 int const length = string->length();
9990
9991 // Perform left trimming if requested.
9992 int left = 0;
9993 UnicodeCache* unicode_cache = isolate->unicode_cache();
9994 if (mode == kTrim || mode == kTrimLeft) {
9995 while (left < length &&
9996 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(left))) {
9997 left++;
9998 }
9999 }
10000
10001 // Perform right trimming if requested.
10002 int right = length;
10003 if (mode == kTrim || mode == kTrimRight) {
10004 while (
10005 right > left &&
10006 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) {
10007 right--;
10008 }
10009 }
10010
10011 return isolate->factory()->NewSubString(string, left, right);
10012 }
9985 10013
9986 bool String::LooksValid() { 10014 bool String::LooksValid() {
9987 if (!GetIsolate()->heap()->Contains(this)) return false; 10015 if (!GetIsolate()->heap()->Contains(this)) return false;
9988 return true; 10016 return true;
9989 } 10017 }
9990 10018
9991 10019
9992 // static 10020 // static
9993 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) { 10021 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) {
9994 if (name->IsString()) return Handle<String>::cast(name); 10022 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) { 18553 if (cell->value() != *new_value) {
18526 cell->set_value(*new_value); 18554 cell->set_value(*new_value);
18527 Isolate* isolate = cell->GetIsolate(); 18555 Isolate* isolate = cell->GetIsolate();
18528 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18556 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18529 isolate, DependentCode::kPropertyCellChangedGroup); 18557 isolate, DependentCode::kPropertyCellChangedGroup);
18530 } 18558 }
18531 } 18559 }
18532 18560
18533 } // namespace internal 18561 } // namespace internal
18534 } // namespace v8 18562 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698