Skip to content

Commit 9edccee

Browse files
authored
refactor(vio): Initialize schema search path statically in VIO_store() to remove unnecessary memory allocations (#8800)
1 parent 8ddd50c commit 9edccee

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/common/classes/init.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ class GlobalPtr : private InstanceControl
147147
FB_NEW InstanceControl::InstanceLink<GlobalPtr, P>(this);
148148
}
149149

150+
template <typename TFunc>
151+
requires(std::invocable<TFunc, MemoryPool&>)
152+
GlobalPtr(TFunc initializationFunc)
153+
{
154+
instance = initializationFunc(*getDefaultMemoryPool());
155+
FB_NEW InstanceControl::InstanceLink<GlobalPtr, P>(this);
156+
}
157+
150158
T* operator->() noexcept
151159
{
152160
return instance;
@@ -160,6 +168,16 @@ class GlobalPtr : private InstanceControl
160168
return instance;
161169
}
162170

171+
T* get() noexcept
172+
{
173+
return instance;
174+
}
175+
176+
const T* get() const noexcept
177+
{
178+
return instance;
179+
}
180+
163181
operator bool() noexcept
164182
{
165183
return instance;

src/jrd/vio.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,7 +4215,10 @@ void VIO_store(thread_db* tdbb, record_param* rpb, jrd_tra* transaction)
42154215
}},
42164216
};
42174217

4218-
ObjectsArray<MetaString> schemaSearchPath({SYSTEM_SCHEMA, PUBLIC_SCHEMA});
4218+
static const GlobalPtr<ObjectsArray<MetaString>> schemaSearchPath([](MemoryPool& pool)
4219+
{
4220+
return FB_NEW_POOL(pool) ObjectsArray<MetaString>(pool, {SYSTEM_SCHEMA, PUBLIC_SCHEMA});
4221+
});
42194222

42204223
if (const auto relSchemaFields = schemaFields.find(relation->rel_id); relSchemaFields != schemaFields.end())
42214224
{
@@ -4234,7 +4237,7 @@ void VIO_store(thread_db* tdbb, record_param* rpb, jrd_tra* transaction)
42344237
{
42354238
MOV_get_metaname(tdbb, &desc, depName.object);
42364239

4237-
if (MET_qualify_existing_name(tdbb, depName, {dependency->objType}, &schemaSearchPath))
4240+
if (MET_qualify_existing_name(tdbb, depName, {dependency->objType}, schemaSearchPath.get()))
42384241
schemaName = depName.schema.c_str();
42394242
}
42404243

0 commit comments

Comments
 (0)