Skip to content

Commit

Permalink
Speed up bootstrap __build_class__ a little bit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tekknolagi committed Mar 23, 2023
1 parent dc0a214 commit d727b03
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions runtime/type-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ RawObject findBuiltinTypeWithName(Thread* thread, const Object& name) {
Object layout(&scope, NoneType::object());
Object type_obj(&scope, NoneType::object());
for (int i = 0; i <= static_cast<int>(LayoutId::kLastBuiltinId); i++) {
layout = runtime->layoutAtSafe(static_cast<LayoutId>(i));
if (layout.isErrorNotFound()) continue;
LayoutId id = static_cast<LayoutId>(i);
if (id == LayoutId::kError) {
// layoutAt(LayoutId::kError) will fail.
continue;
}
layout = runtime->layoutAt(id);
if (layout == SmallInt::fromWord(0)) {
// Indicates an invalid LayoutId.
continue;
}
type_obj = Layout::cast(*layout).describedType();
if (!type_obj.isType()) continue;
if (Type::cast(*type_obj).name() == name) {
Expand Down

0 comments on commit d727b03

Please sign in to comment.