[pygobject/llvm: 13/17] [llvm] Reuse GModules
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/llvm: 13/17] [llvm] Reuse GModules
- Date: Wed, 21 Jul 2010 22:35:57 +0000 (UTC)
commit bd4e43c96596dadb7db03b08c4b01c1a0095f9ed
Author: Johan Dahlin <johan gnome org>
Date: Thu Jul 8 18:05:19 2010 -0300
[llvm] Reuse GModules
Instead of reopening them on each access
gi/llvm-compiler.cpp | 14 +++++++++++---
gi/llvm-compiler.h | 3 +++
2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/gi/llvm-compiler.cpp b/gi/llvm-compiler.cpp
index 563e4e0..52b09a2 100644
--- a/gi/llvm-compiler.cpp
+++ b/gi/llvm-compiler.cpp
@@ -550,11 +550,19 @@ void *
LLVMCompiler::getNativeAddress(GIFunctionInfo *info)
{
void * nativeAddress;
+ const char * namespace_ = g_base_info_get_namespace((GIBaseInfo*)info);
+ moduleMapType::iterator i = mGModules.find(namespace_);
+ GModule *module;
+ if (i == mGModules.end()) {
+ const gchar * shlib = g_irepository_get_shared_library(NULL, namespace_);
+ module = g_module_open(shlib, G_MODULE_BIND_LAZY);
+ mGModules.insert(std::make_pair(namespace_, module));
+ } else {
+ module= i->second;
+ }
- const gchar * shlib = g_irepository_get_shared_library(NULL, g_base_info_get_namespace((GIBaseInfo*)info));
const gchar * symbol = g_function_info_get_symbol(info);
- GModule *m = g_module_open(shlib, G_MODULE_BIND_LAZY);
- g_module_symbol(m, symbol, &nativeAddress);
+ g_module_symbol(module, symbol, &nativeAddress);
return nativeAddress;
}
diff --git a/gi/llvm-compiler.h b/gi/llvm-compiler.h
index c0494bb..8bacf61 100644
--- a/gi/llvm-compiler.h
+++ b/gi/llvm-compiler.h
@@ -31,12 +31,15 @@
#include <llvm/Support/IRBuilder.h>
namespace pygi {
+ // typelib namespace -> GModule
+ typedef std::map<std::string, GModule*> moduleMapType;
class LLVMCompiler {
private:
llvm::LLVMContext &mCtx;
llvm::ExecutionEngine *mEE;
llvm::Module *mModule;
+ moduleMapType mGModules;
llvm::ExecutionEngine* createExecutionEngine(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]