From 1fb0de9e0007c2c6c4ba3e0baa151d4b9a7e8f59 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Oct 2021 18:47:12 +0200 Subject: [PATCH] Don't call Swig_scopename_prefix() unnecessarily No real changes, just make the code do what the comment said it did and only use the namespace as prefix when "nspace" feature is on instead of always trying to use it as prefix and then resetting it. This required adding default ctor and assignment operator from raw pointer to scoped_dohptr, but they can be useful elsewhere too, while the actual code in getGlobalWrapperName() is simpler and more readable now. No real changes. --- Source/Modules/c.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 61ffedd31..2e7931332 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -33,6 +33,7 @@ namespace class scoped_dohptr { public: + scoped_dohptr() : obj_(NULL) {} explicit scoped_dohptr(DOH* obj) : obj_(obj) {} ~scoped_dohptr() { Delete(obj_); } @@ -49,6 +50,16 @@ public: return *this; } + // Assignment operator takes ownership of the pointer, just as the ctor does. + scoped_dohptr& operator=(DOH* obj) { + if (obj != obj_) { + Delete(obj_); + obj_ = obj; + } + + return *this; + } + DOH* get() const { return obj_; } DOH* release() const /* not really */ { @@ -196,13 +207,12 @@ public: String *getGlobalWrapperName(Node *n, String *name) const { // Use namespace as the prefix if feature:nspace is in use. - scoped_dohptr scopename_prefix(Swig_scopename_prefix(Getattr(n, "name"))); - if (scopename_prefix) { - if (GetFlag(parentNode(n), "feature:nspace")) { + scoped_dohptr scopename_prefix; + if (GetFlag(parentNode(n), "feature:nspace")) { + scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + if (scopename_prefix) { scoped_dohptr mangled_prefix(Swig_string_mangle(scopename_prefix)); scopename_prefix = mangled_prefix; - } else { - scopename_prefix.reset(); } }