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

Side by Side Diff: vm/class_table.cc

Issue 9965042: - Add a class index to the classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/class_table.h"
6 #include "vm/flags.h"
7 #include "vm/object.h"
8 #include "vm/raw_object.h"
9
10 namespace dart {
11
12 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
13
14 ClassTable::ClassTable()
15 : top_(kNumPredefinedKinds), capacity_(initial_capacity_), table_(NULL) {
16 table_ = reinterpret_cast<RawClass**>(calloc(capacity_,
17 sizeof(RawClass*))); // NOLINT
18 }
19
20
21 ClassTable::~ClassTable() {
22 free(table_);
23 }
24
25
26 void ClassTable::Register(const Class& cls) {
27 intptr_t index = cls.index();
28 if (index != kIllegalObjectKind) {
29 ASSERT(index > 0);
30 ASSERT(index < kNumPredefinedKinds);
31 ASSERT(table_[index] == 0);
32 table_[index] = cls.raw();
33 } else {
34 cls.set_index(top_);
35 table_[top_] = cls.raw();
36 top_++; // Increment next index.
37 ASSERT(top_ < capacity_);
38 }
39 }
40
41
42 void ClassTable::Print() {
43 Class& cls = Class::Handle();
44 String& name = String::Handle();
45
46 for (intptr_t i = 1; i < top_; i++) {
47 cls = At(i);
48 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
49 name = cls.Name();
50 OS::Print("%d: %s\n", i, name.ToCString());
51 }
52 }
53 }
54
55 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698