Skip to content

Commit

Permalink
fix namespace scope lookup to not create extraneous null entries
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Nov 1, 2024
1 parent 99d8c49 commit 6424ffb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/chuck_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "chuck_errmsg.h"



//-----------------------------------------------------------------------------
// name: enum te_Type
// desc: basic, default ChucK types
Expand Down Expand Up @@ -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<S_Symbol, Chuck_VM_Object *> * b = scope.back();
std::map<S_Symbol, Chuck_VM_Object *>::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()) )
Expand All @@ -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<S_Symbol, Chuck_VM_Object *> * b = scope[i-1];
std::map<S_Symbol, Chuck_VM_Object *>::iterator it = b->find(xid);
val = it != b->end() ? it->second : NULL;
if( val ) break;
}

Expand All @@ -199,7 +205,10 @@ struct Chuck_Scope
}
else
{
val = (*scope.front())[xid];
// look front
std::map<S_Symbol, Chuck_VM_Object *> * b = scope.front();
std::map<S_Symbol, Chuck_VM_Object *>::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];
Expand Down

0 comments on commit 6424ffb

Please sign in to comment.