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

Side by Side Diff: src/interface.cc

Issue 335293004: New try: Parser: Delay internalizing strings and values (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased (trivial) Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/interface.h ('k') | src/objects.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/interface.h" 7 #include "src/interface.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 static bool Match(void* key1, void* key2) {
13 String* name1 = *static_cast<String**>(key1);
14 String* name2 = *static_cast<String**>(key2);
15 ASSERT(name1->IsInternalizedString());
16 ASSERT(name2->IsInternalizedString());
17 return name1 == name2;
18 }
19
20
21 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { 12 Interface* Interface::Lookup(Handle<String> name, Zone* zone) {
22 ASSERT(IsModule()); 13 ASSERT(IsModule());
23 ZoneHashMap* map = Chase()->exports_; 14 ZoneHashMap* map = Chase()->exports_;
24 if (map == NULL) return NULL; 15 if (map == NULL) return NULL;
25 ZoneAllocationPolicy allocator(zone); 16 ZoneAllocationPolicy allocator(zone);
26 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, 17 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false,
27 allocator); 18 allocator);
28 if (p == NULL) return NULL; 19 if (p == NULL) return NULL;
29 ASSERT(*static_cast<String**>(p->key) == *name); 20 ASSERT(*static_cast<String**>(p->key) == *name);
30 ASSERT(p->value != NULL); 21 ASSERT(p->value != NULL);
31 return static_cast<Interface*>(p->value); 22 return static_cast<Interface*>(p->value);
32 } 23 }
33 24
34 25
35 #ifdef DEBUG 26 #ifdef DEBUG
36 // Current nesting depth for debug output. 27 // Current nesting depth for debug output.
37 class Nesting { 28 class Nesting {
38 public: 29 public:
39 Nesting() { current_ += 2; } 30 Nesting() { current_ += 2; }
40 ~Nesting() { current_ -= 2; } 31 ~Nesting() { current_ -= 2; }
41 static int current() { return current_; } 32 static int current() { return current_; }
42 private: 33 private:
43 static int current_; 34 static int current_;
44 }; 35 };
45 36
46 int Nesting::current_ = 0; 37 int Nesting::current_ = 0;
47 #endif 38 #endif
48 39
49 40
50 void Interface::DoAdd( 41 void Interface::DoAdd(const void* name, uint32_t hash, Interface* interface,
51 void* name, uint32_t hash, Interface* interface, Zone* zone, bool* ok) { 42 Zone* zone, bool* ok) {
52 MakeModule(ok); 43 MakeModule(ok);
53 if (!*ok) return; 44 if (!*ok) return;
54 45
55 #ifdef DEBUG 46 #ifdef DEBUG
56 if (FLAG_print_interface_details) { 47 if (FLAG_print_interface_details) {
57 PrintF("%*s# Adding...\n", Nesting::current(), ""); 48 PrintF("%*s# Adding...\n", Nesting::current(), "");
58 PrintF("%*sthis = ", Nesting::current(), ""); 49 PrintF("%*sthis = ", Nesting::current(), "");
59 this->Print(Nesting::current()); 50 this->Print(Nesting::current());
60 PrintF("%*s%s : ", Nesting::current(), "", 51 const AstRawString* symbol = static_cast<const AstRawString*>(name);
61 (*static_cast<String**>(name))->ToAsciiArray()); 52 PrintF("%*s%.*s : ", Nesting::current(), "", symbol->length(),
53 symbol->raw_data());
62 interface->Print(Nesting::current()); 54 interface->Print(Nesting::current());
63 } 55 }
64 #endif 56 #endif
65 57
66 ZoneHashMap** map = &Chase()->exports_; 58 ZoneHashMap** map = &Chase()->exports_;
67 ZoneAllocationPolicy allocator(zone); 59 ZoneAllocationPolicy allocator(zone);
68 60
69 if (*map == NULL) { 61 if (*map == NULL) {
70 *map = new(zone->New(sizeof(ZoneHashMap))) 62 *map = new(zone->New(sizeof(ZoneHashMap)))
71 ZoneHashMap(Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); 63 ZoneHashMap(ZoneHashMap::PointersMatch,
64 ZoneHashMap::kDefaultHashMapCapacity, allocator);
72 } 65 }
73 66
74 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator); 67 ZoneHashMap::Entry* p =
68 (*map)->Lookup(const_cast<void*>(name), hash, !IsFrozen(), allocator);
75 if (p == NULL) { 69 if (p == NULL) {
76 // This didn't have name but was frozen already, that's an error. 70 // This didn't have name but was frozen already, that's an error.
77 *ok = false; 71 *ok = false;
78 } else if (p->value == NULL) { 72 } else if (p->value == NULL) {
79 p->value = interface; 73 p->value = interface;
80 } else { 74 } else {
81 #ifdef DEBUG 75 #ifdef DEBUG
82 Nesting nested; 76 Nesting nested;
83 #endif 77 #endif
84 static_cast<Interface*>(p->value)->Unify(interface, zone, ok); 78 static_cast<Interface*>(p->value)->Unify(interface, zone, ok);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); 207 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray());
214 interface->Print(n0 + 2); 208 interface->Print(n0 + 2);
215 } 209 }
216 PrintF("%*s}\n", n0, ""); 210 PrintF("%*s}\n", n0, "");
217 } 211 }
218 } 212 }
219 } 213 }
220 #endif 214 #endif
221 215
222 } } // namespace v8::internal 216 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/interface.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698