Skip to content

Commit d727b03

Browse files
committed
Speed up bootstrap __build_class__ a little bit
Since we're iterating over the layouts table one by one, and the layouts table will always be at least LayoutId::kLastBuiltinId layouts long, use `Runtime::layoutAt` instead of `Runtime::layoutAtSafe`, which does a bunch of checks. This search is still linear and kind of long, though.
1 parent dc0a214 commit d727b03

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

runtime/type-builtins.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,16 @@ RawObject findBuiltinTypeWithName(Thread* thread, const Object& name) {
8282
Object layout(&scope, NoneType::object());
8383
Object type_obj(&scope, NoneType::object());
8484
for (int i = 0; i <= static_cast<int>(LayoutId::kLastBuiltinId); i++) {
85-
layout = runtime->layoutAtSafe(static_cast<LayoutId>(i));
86-
if (layout.isErrorNotFound()) continue;
85+
LayoutId id = static_cast<LayoutId>(i);
86+
if (id == LayoutId::kError) {
87+
// layoutAt(LayoutId::kError) will fail.
88+
continue;
89+
}
90+
layout = runtime->layoutAt(id);
91+
if (layout == SmallInt::fromWord(0)) {
92+
// Indicates an invalid LayoutId.
93+
continue;
94+
}
8795
type_obj = Layout::cast(*layout).describedType();
8896
if (!type_obj.isType()) continue;
8997
if (Type::cast(*type_obj).name() == name) {

0 commit comments

Comments
 (0)