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

Side by Side Diff: src/objects.cc

Issue 7039037: Create stand-alone json parser (including scanner). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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 | « src/objects.h ('k') | src/parser.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 5449 matching lines...) Expand 10 before | Expand all | Expand 10 after
5460 uc32 r = decoder->GetNext(); 5460 uc32 r = decoder->GetNext();
5461 if (Get(i) != r) return false; 5461 if (Get(i) != r) return false;
5462 } 5462 }
5463 return i == slen && !decoder->has_more(); 5463 return i == slen && !decoder->has_more();
5464 } 5464 }
5465 5465
5466 5466
5467 bool String::IsAsciiEqualTo(Vector<const char> str) { 5467 bool String::IsAsciiEqualTo(Vector<const char> str) {
5468 int slen = length(); 5468 int slen = length();
5469 if (str.length() != slen) return false; 5469 if (str.length() != slen) return false;
5470 for (int i = 0; i < slen; i++) { 5470 if (this->IsSeqAsciiString()) {
5471 if (Get(i) != static_cast<uint16_t>(str[i])) return false; 5471 SeqAsciiString* seq = SeqAsciiString::cast(this);
5472 char* ch = seq->GetChars();
5473 for (int i = 0; i < slen; i++, ch++) {
5474 if (*ch != str[i]) return false;
5475 }
5476 } else {
5477 for (int i = 0; i < slen; i++) {
5478 if (Get(i) != static_cast<uint16_t>(str[i])) return false;
5479 }
5472 } 5480 }
5473 return true; 5481 return true;
5474 } 5482 }
5475 5483
5476 5484
5477 bool String::IsTwoByteEqualTo(Vector<const uc16> str) { 5485 bool String::IsTwoByteEqualTo(Vector<const uc16> str) {
5478 int slen = length(); 5486 int slen = length();
5479 if (str.length() != slen) return false; 5487 if (str.length() != slen) return false;
5480 for (int i = 0; i < slen; i++) { 5488 for (int i = 0; i < slen; i++) {
5481 if (Get(i) != str[i]) return false; 5489 if (Get(i) != str[i]) return false;
(...skipping 3207 matching lines...) Expand 10 before | Expand all | Expand 10 after
8689 return String::cast(string)->IsAsciiEqualTo(string_); 8697 return String::cast(string)->IsAsciiEqualTo(string_);
8690 } 8698 }
8691 8699
8692 MaybeObject* AsObject() { 8700 MaybeObject* AsObject() {
8693 if (hash_field_ == 0) Hash(); 8701 if (hash_field_ == 0) Hash();
8694 return HEAP->AllocateAsciiSymbol(string_, hash_field_); 8702 return HEAP->AllocateAsciiSymbol(string_, hash_field_);
8695 } 8703 }
8696 }; 8704 };
8697 8705
8698 8706
8707 class SubStringAsciiSymbolKey : public HashTableKey {
8708 public:
8709 explicit SubStringAsciiSymbolKey(Handle<SeqAsciiString> string,
8710 int from,
8711 int length)
8712 : string_(string), from_(from), length_(length) { }
8713
8714 uint32_t Hash() {
8715 ASSERT(length_ >= 0);
8716 ASSERT(from_ + length_ <= string_->length());
8717 StringHasher hasher(length_);
8718
8719 // Very long strings have a trivial hash that doesn't inspect the
8720 // string contents.
8721 if (hasher.has_trivial_hash()) {
8722 hash_field_ = hasher.GetHashField();
8723 } else {
8724 int i = 0;
8725 // Do the iterative array index computation as long as there is a
8726 // chance this is an array index.
8727 while (i < length_ && hasher.is_array_index()) {
8728 hasher.AddCharacter(static_cast<uc32>(
8729 string_->SeqAsciiStringGet(i + from_)));
8730 i++;
8731 }
8732
8733 // Process the remaining characters without updating the array
8734 // index.
8735 while (i < length_) {
8736 hasher.AddCharacterNoIndex(static_cast<uc32>(
8737 string_->SeqAsciiStringGet(i + from_)));
8738 i++;
8739 }
8740 hash_field_ = hasher.GetHashField();
8741 }
8742
8743 uint32_t result = hash_field_ >> String::kHashShift;
8744 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
8745 return result;
8746 }
8747
8748
8749 uint32_t HashForObject(Object* other) {
8750 return String::cast(other)->Hash();
8751 }
8752
8753 bool IsMatch(Object* string) {
8754 Vector<const char> chars(string_->GetChars() + from_, length_);
8755 return String::cast(string)->IsAsciiEqualTo(chars);
8756 }
8757
8758 MaybeObject* AsObject() {
8759 if (hash_field_ == 0) Hash();
8760 Vector<const char> chars(string_->GetChars() + from_, length_);
8761 return HEAP->AllocateAsciiSymbol(chars, hash_field_);
8762 }
8763
8764 private:
8765 Handle<SeqAsciiString> string_;
8766 int from_;
8767 int length_;
8768 uint32_t hash_field_;
8769 };
8770
8771
8699 class TwoByteSymbolKey : public SequentialSymbolKey<uc16> { 8772 class TwoByteSymbolKey : public SequentialSymbolKey<uc16> {
8700 public: 8773 public:
8701 explicit TwoByteSymbolKey(Vector<const uc16> str) 8774 explicit TwoByteSymbolKey(Vector<const uc16> str)
8702 : SequentialSymbolKey<uc16>(str) { } 8775 : SequentialSymbolKey<uc16>(str) { }
8703 8776
8704 bool IsMatch(Object* string) { 8777 bool IsMatch(Object* string) {
8705 return String::cast(string)->IsTwoByteEqualTo(string_); 8778 return String::cast(string)->IsTwoByteEqualTo(string_);
8706 } 8779 }
8707 8780
8708 MaybeObject* AsObject() { 8781 MaybeObject* AsObject() {
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
9483 } 9556 }
9484 9557
9485 9558
9486 MaybeObject* SymbolTable::LookupAsciiSymbol(Vector<const char> str, 9559 MaybeObject* SymbolTable::LookupAsciiSymbol(Vector<const char> str,
9487 Object** s) { 9560 Object** s) {
9488 AsciiSymbolKey key(str); 9561 AsciiSymbolKey key(str);
9489 return LookupKey(&key, s); 9562 return LookupKey(&key, s);
9490 } 9563 }
9491 9564
9492 9565
9566 MaybeObject* SymbolTable::LookupSubStringAsciiSymbol(Handle<SeqAsciiString> str,
9567 int from,
9568 int length,
9569 Object** s) {
9570 SubStringAsciiSymbolKey key(str, from, length);
9571 return LookupKey(&key, s);
9572 }
9573
9574
9493 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str, 9575 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str,
9494 Object** s) { 9576 Object** s) {
9495 TwoByteSymbolKey key(str); 9577 TwoByteSymbolKey key(str);
9496 return LookupKey(&key, s); 9578 return LookupKey(&key, s);
9497 } 9579 }
9498 9580
9499 MaybeObject* SymbolTable::LookupKey(HashTableKey* key, Object** s) { 9581 MaybeObject* SymbolTable::LookupKey(HashTableKey* key, Object** s) {
9500 int entry = FindEntry(key); 9582 int entry = FindEntry(key);
9501 9583
9502 // Symbol already in table. 9584 // Symbol already in table.
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
10430 if (break_point_objects()->IsUndefined()) return 0; 10512 if (break_point_objects()->IsUndefined()) return 0;
10431 // Single beak point. 10513 // Single beak point.
10432 if (!break_point_objects()->IsFixedArray()) return 1; 10514 if (!break_point_objects()->IsFixedArray()) return 1;
10433 // Multiple break points. 10515 // Multiple break points.
10434 return FixedArray::cast(break_point_objects())->length(); 10516 return FixedArray::cast(break_point_objects())->length();
10435 } 10517 }
10436 #endif 10518 #endif
10437 10519
10438 10520
10439 } } // namespace v8::internal 10521 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698