mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 16:07:52 -05:00
make cached instance
This commit is contained in:
parent
63e9b4c5f7
commit
e44a4bb513
1 changed files with 7 additions and 10 deletions
|
@ -29,7 +29,9 @@ namespace geode::addresser {
|
||||||
|
|
||||||
template <class Class>
|
template <class Class>
|
||||||
Class* friendCreate(typename std::void_t<decltype(static_cast<Class* (*)()>(&Class::create))>*) {
|
Class* friendCreate(typename std::void_t<decltype(static_cast<Class* (*)()>(&Class::create))>*) {
|
||||||
return Class::create();
|
auto ret = Class::create();
|
||||||
|
ret->retain();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Class>
|
template <class Class>
|
||||||
|
@ -94,14 +96,10 @@ namespace geode::addresser {
|
||||||
return ins;
|
return ins;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <HasCreate Class>
|
|
||||||
static void releaseInstance(Class* ins) {}
|
|
||||||
|
|
||||||
template <class Class>
|
template <class Class>
|
||||||
static void releaseInstance(Class* ins) {
|
static Class* cachedInstance() {
|
||||||
// And we delete the new instance because we are good girls
|
static auto ret = generateInstance<Class>();
|
||||||
// and we don't leak memories
|
return ret;
|
||||||
operator delete(ins);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +113,7 @@ namespace geode::addresser {
|
||||||
|
|
||||||
auto index = indexOf(func);
|
auto index = indexOf(func);
|
||||||
auto thunk = thunkOf(func);
|
auto thunk = thunkOf(func);
|
||||||
auto ins = generateInstance<T>();
|
auto ins = cachedInstance<T>();
|
||||||
|
|
||||||
// log::debug("[[" + utils::intToHex((void*)ins) + " + " + utils::intToHex(thunk) + "] +
|
// log::debug("[[" + utils::intToHex((void*)ins) + " + " + utils::intToHex(thunk) + "] +
|
||||||
// " + utils::intToHex(index) + "]");
|
// " + utils::intToHex(index) + "]");
|
||||||
|
@ -136,7 +134,6 @@ namespace geode::addresser {
|
||||||
address = *reinterpret_cast<uintptr_t*>(address);
|
address = *reinterpret_cast<uintptr_t*>(address);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
releaseInstance<T>(ins);
|
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue