From d727b03abf2db8b2d79ac0e3dc3bec6a0be55d44 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Thu, 23 Mar 2023 16:04:10 -0400 Subject: [PATCH] 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. --- runtime/type-builtins.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/type-builtins.cpp b/runtime/type-builtins.cpp index a5f932f90..2b24e96ba 100644 --- a/runtime/type-builtins.cpp +++ b/runtime/type-builtins.cpp @@ -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(LayoutId::kLastBuiltinId); i++) { - layout = runtime->layoutAtSafe(static_cast(i)); - if (layout.isErrorNotFound()) continue; + LayoutId id = static_cast(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) {