Skip to content

Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor fixes.
  • Loading branch information
CookStar committed Jun 17, 2023
commit 3d5311d32fa431f44bf388916db989c78d4b3a75
59 changes: 25 additions & 34 deletions addons/source-python/packages/source-python/memory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,40 +619,34 @@ def virtual_function(
if return_type not in DataType.values:
return_type = self.create_converter(return_type)

# Store the function cache
funcs = {}

class fget(object):
def __set_name__(fget_self, owner, name):
fget_self.name = name

def __get__(fget_self, obj, cls=None):
"""Return the virtual function."""
if obj is None:
return fget_self

# Get the vtable address
address = obj._ptr().get_pointer().address
# Search function cache by vtable address
func = funcs.get(address, None)

if func is None:
# Create the virtual function cache it
func = obj.make_virtual_function(
index,
convention,
args,
return_type
)
funcs[address] = func
def fget(ptr):
"""Return the virtual function."""
# Get the vtable address
address = ptr._ptr().get_pointer().address
# Search function cache by vtable address
func = funcs.get(address, None)

if func is None:
# Create the virtual function cache it
func = ptr.make_virtual_function(
index,
convention,
args,
return_type
)
funcs[address] = func

# Wrap it using MemberFunction, so we don't have to pass the this
# pointer anymore
func = MemberFunction(self, return_type, func, obj)
func.__doc__ = doc
# Wrap it using MemberFunction, so we don't have to pass the this
# pointer anymore
m_func = MemberFunction(self, return_type, func, ptr)
m_func.__doc__ = doc

return func
return m_func

return fget()
return property(fget, None, None, doc)

def function(
self, identifier, args=(), return_type=DataType.VOID,
Expand All @@ -669,9 +663,6 @@ def function(
func = None

class fget(object):
def __set_name__(fget_self, owner, name):
fget_self.name = name

def __get__(fget_self, obj, cls=None):
nonlocal func
if cls is None:
Expand All @@ -697,8 +688,8 @@ def __get__(fget_self, obj, cls=None):

# Called with a this pointer?
if obj is not None:
# Wrap the function using MemberFunction,
# so we don't have to pass the this pointer anymore
# Wrap the function using MemberFunction, so we don't have
# to pass the this pointer anymore
m_func = MemberFunction(self, return_type, func, obj)
m_func.__doc__ = doc

Expand Down