From 6424ffb8617a364a2cf001511b6c76544385d68f Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Thu, 31 Oct 2024 22:36:42 -0700 Subject: [PATCH] fix namespace scope lookup to not create extraneous null entries --- src/core/chuck_type.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/chuck_type.h b/src/core/chuck_type.h index 510cd523b..dee6d2184 100644 --- a/src/core/chuck_type.h +++ b/src/core/chuck_type.h @@ -40,7 +40,6 @@ #include "chuck_errmsg.h" - //----------------------------------------------------------------------------- // name: enum te_Type // desc: basic, default ChucK types @@ -175,11 +174,15 @@ struct Chuck_Scope // -1 base, 0 current, 1 climb T lookup( S_Symbol xid, t_CKINT climb = 1 ) { - Chuck_VM_Object * val = NULL; assert( scope.size() != 0 ); + Chuck_VM_Object * val = NULL; + assert( scope.size() != 0 ); if( climb == 0 ) { - val = (*scope.back())[xid]; + // find key + std::map * b = scope.back(); + std::map::iterator it = b->find(xid); + val = it != b->end() ? it->second : NULL; // look in commit buffer if the back is the front if( !val && scope.back() == scope.front() && (commit_map.find(xid) != commit_map.end()) ) @@ -189,7 +192,10 @@ struct Chuck_Scope { for( t_CKUINT i = scope.size(); i > 0; i-- ) { - val = (*scope[i - 1])[xid]; + // find key + std::map * b = scope[i-1]; + std::map::iterator it = b->find(xid); + val = it != b->end() ? it->second : NULL; if( val ) break; } @@ -199,7 +205,10 @@ struct Chuck_Scope } else { - val = (*scope.front())[xid]; + // look front + std::map * b = scope.front(); + std::map::iterator it = b->find(xid); + val = it != b->end() ? it->second : NULL; // look in commit buffer if( !val && (commit_map.find(xid) != commit_map.end()) ) val = commit_map[xid];