[PATCH 2/2] Avoid having to search for our magic twice



In gperl_get_object_check, keep around and use the result of gperl_find_mg
instead of calling it a second time (and having to traverse the whole magic list
again) via gperl_get_object.
---
 GObject.xs |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/GObject.xs b/GObject.xs
index 52e5647..8e9653e 100644
--- a/GObject.xs
+++ b/GObject.xs
@@ -992,6 +992,7 @@ GObject *
 gperl_get_object_check (SV * sv,
                        GType gtype)
 {
+       MAGIC *mg;
        const char * package;
        package = gperl_object_package_from_type (gtype);
        if (!package)
@@ -1001,12 +1002,12 @@ gperl_get_object_check (SV * sv,
                croak ("%s is not of type %s",
                       gperl_format_variable_for_output (sv),
                       package);
-       if (!_gperl_find_mg (SvRV (sv)))
+       if (!(mg = _gperl_find_mg (SvRV (sv))))
                croak ("%s is not a proper Glib::Object "
                       "(it doesn't contain the right magic)",
                       gperl_format_variable_for_output (sv));
 
-       return gperl_get_object (sv);
+       return (GObject *) mg->mg_ptr;
 }
 
 
-- 
1.7.2.3




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]