OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 4286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4297 | 4297 |
4298 bool String::IsOneByte() const { | 4298 bool String::IsOneByte() const { |
4299 i::Handle<i::String> str = Utils::OpenHandle(this); | 4299 i::Handle<i::String> str = Utils::OpenHandle(this); |
4300 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) { | 4300 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) { |
4301 return false; | 4301 return false; |
4302 } | 4302 } |
4303 return str->HasOnlyOneByteChars(); | 4303 return str->HasOnlyOneByteChars(); |
4304 } | 4304 } |
4305 | 4305 |
4306 | 4306 |
4307 class DefinitelyContainsOnlyOneByteHelper { | |
4308 public: | |
4309 DefinitelyContainsOnlyOneByteHelper() : is_one_byte_(true) {} | |
4310 bool Check(i::String* string) { | |
4311 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); | |
4312 if (cons_string == NULL) return is_one_byte_; | |
4313 return CheckCons(cons_string); | |
4314 } | |
4315 void VisitOneByteString(const uint8_t* chars, int length) { | |
4316 // Nothing to do. | |
4317 } | |
4318 void VisitTwoByteString(const uint16_t* chars, int length) { | |
4319 for (int i = 0; i < length; i++) { | |
4320 if (chars[i] >> 8) { | |
4321 is_one_byte_ = false; | |
4322 return; | |
4323 } | |
4324 } | |
4325 } | |
4326 | |
4327 private: | |
4328 bool CheckCons(i::ConsString* cons_string) { | |
4329 while (true) { | |
4330 // Check left side if flat. | |
4331 i::String* left = cons_string->first(); | |
4332 i::ConsString* left_as_cons = | |
4333 i::String::VisitFlat(this, left, 0); | |
4334 if (!is_one_byte_) return false; | |
4335 // Check right side if flat. | |
4336 i::String* right = cons_string->second(); | |
4337 i::ConsString* right_as_cons = | |
4338 i::String::VisitFlat(this, right, 0); | |
4339 if (!is_one_byte_) return false; | |
4340 // Standard recurse/iterate trick. | |
4341 // Falls through to the cases below for the iteration. | |
4342 if (left_as_cons != NULL && right_as_cons != NULL) { | |
4343 if (left->length() < right->length()) { | |
4344 CheckCons(right_as_cons); | |
4345 right_as_cons = NULL; | |
Yang
2013/06/06 09:12:59
I think it's a bit easier to read if you just set
dcarney
2013/06/06 09:17:26
okay
| |
4346 } else { | |
4347 CheckCons(left_as_cons); | |
4348 left_as_cons = NULL; | |
4349 } | |
4350 // Check fast return. | |
4351 if (!is_one_byte_) return false; | |
4352 } | |
4353 // Descend left in place. | |
4354 if (left_as_cons != NULL) { | |
4355 cons_string = left_as_cons; | |
4356 continue; | |
4357 } | |
4358 // Descend right in place. | |
4359 if (right_as_cons != NULL) { | |
4360 cons_string = right_as_cons; | |
4361 continue; | |
4362 } | |
4363 // Terminate. | |
4364 break; | |
4365 } | |
4366 return is_one_byte_; | |
4367 } | |
4368 bool is_one_byte_; | |
4369 DISALLOW_COPY_AND_ASSIGN(DefinitelyContainsOnlyOneByteHelper); | |
4370 }; | |
4371 | |
4372 | |
4373 bool String::DefinitelyContainsOnlyOneByte() const { | |
4374 i::Handle<i::String> str = Utils::OpenHandle(this); | |
4375 if (IsDeadCheck(str->GetIsolate(), | |
4376 "v8::String::DefinitelyContainsOnlyOneByte()")) { | |
4377 return false; | |
4378 } | |
4379 if (str->HasOnlyOneByteChars()) return true; | |
4380 DefinitelyContainsOnlyOneByteHelper helper; | |
4381 return helper.Check(*str); | |
Yang
2013/06/06 09:12:59
If we find that the string only contains one byte
dcarney
2013/06/06 09:17:26
will do
| |
4382 } | |
4383 | |
4384 | |
4307 class Utf8LengthHelper : public i::AllStatic { | 4385 class Utf8LengthHelper : public i::AllStatic { |
4308 public: | 4386 public: |
4309 enum State { | 4387 enum State { |
4310 kEndsWithLeadingSurrogate = 1 << 0, | 4388 kEndsWithLeadingSurrogate = 1 << 0, |
4311 kStartsWithTrailingSurrogate = 1 << 1, | 4389 kStartsWithTrailingSurrogate = 1 << 1, |
4312 kLeftmostEdgeIsCalculated = 1 << 2, | 4390 kLeftmostEdgeIsCalculated = 1 << 2, |
4313 kRightmostEdgeIsCalculated = 1 << 3, | 4391 kRightmostEdgeIsCalculated = 1 << 3, |
4314 kLeftmostEdgeIsSurrogate = 1 << 4, | 4392 kLeftmostEdgeIsSurrogate = 1 << 4, |
4315 kRightmostEdgeIsSurrogate = 1 << 5 | 4393 kRightmostEdgeIsSurrogate = 1 << 5 |
4316 }; | 4394 }; |
(...skipping 3538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7855 | 7933 |
7856 v->VisitPointers(blocks_.first(), first_block_limit_); | 7934 v->VisitPointers(blocks_.first(), first_block_limit_); |
7857 | 7935 |
7858 for (int i = 1; i < blocks_.length(); i++) { | 7936 for (int i = 1; i < blocks_.length(); i++) { |
7859 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 7937 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
7860 } | 7938 } |
7861 } | 7939 } |
7862 | 7940 |
7863 | 7941 |
7864 } } // namespace v8::internal | 7942 } } // namespace v8::internal |
OLD | NEW |