exposed moo_lookupdic_noseterr() which doesn't set error information upon failure so as to avoid setting error information unnecessarily during method lookup(moo_findmethod(), etc)
This commit is contained in:
		@ -197,7 +197,7 @@ oops:
 | 
			
		||||
	return MOO_NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static moo_oop_association_t lookup (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
 | 
			
		||||
moo_oop_association_t moo_lookupdic_noseterr (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
 | 
			
		||||
{
 | 
			
		||||
	/* this is special version of moo_getatsysdic() that performs
 | 
			
		||||
	 * lookup using a plain string specified */
 | 
			
		||||
@ -228,10 +228,22 @@ static moo_oop_association_t lookup (moo_t* moo, moo_oop_dic_t dic, const moo_oo
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* when value is MOO_NULL, perform no insertion */
 | 
			
		||||
	moo_seterrbfmt (moo, MOO_ENOENT, "unable to find %.*js in a dictionary", name->len, name->ptr);
 | 
			
		||||
 | 
			
		||||
	/* moo_seterrXXX() is not called here. the dictionary lookup is very frequent 
 | 
			
		||||
	 * and so is lookup failure. for instance, moo_findmethod() calls this over 
 | 
			
		||||
	 * a class chain. there might be a failure at each class level. it's waste to
 | 
			
		||||
	 * set the error information whenever the failure occurs.
 | 
			
		||||
	 * the caller of this function must set the error information upon failure */
 | 
			
		||||
	return MOO_NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static MOO_INLINE moo_oop_association_t lookup (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
 | 
			
		||||
{
 | 
			
		||||
	moo_oop_association_t ass = moo_lookupdic_noseterr(moo, dic, name);
 | 
			
		||||
	if (!ass) moo_seterrbfmt(moo, MOO_ENOENT, "unable to find %.*js in a dictionary", name->len, name->ptr);
 | 
			
		||||
	return ass;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
moo_oop_association_t moo_putatsysdic (moo_t* moo, moo_oop_t key, moo_oop_t value)
 | 
			
		||||
{
 | 
			
		||||
	MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol);
 | 
			
		||||
 | 
			
		||||
@ -1635,7 +1635,7 @@ static MOO_INLINE moo_oop_method_t find_method_in_class (moo_t* moo, moo_oop_cla
 | 
			
		||||
	MOO_ASSERT (moo, (moo_oop_t)mthdic != moo->_nil); 
 | 
			
		||||
	MOO_ASSERT (moo, MOO_CLASSOF(moo, mthdic) == moo->_method_dictionary);
 | 
			
		||||
 | 
			
		||||
	ass = (moo_oop_association_t)moo_lookupdic(moo, mthdic, name);
 | 
			
		||||
	ass = (moo_oop_association_t)moo_lookupdic_noseterr(moo, mthdic, name);
 | 
			
		||||
	if (ass) 
 | 
			
		||||
	{
 | 
			
		||||
		/* found the method */
 | 
			
		||||
@ -1711,7 +1711,6 @@ moo_oop_method_t moo_findmethod (moo_t* moo, moo_oop_t receiver, const moo_oocs_
 | 
			
		||||
		 * otherwise c points to a class object */
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/* [IMPORT] the method lookup logic should be the same as ciim_on_each_method() in comp.c */
 | 
			
		||||
	mth = find_method_in_class_chain(moo, c, mth_type, message);
 | 
			
		||||
	if (mth) return mth;
 | 
			
		||||
 | 
			
		||||
@ -1070,7 +1070,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
 | 
			
		||||
		total_bytes = MOO_SIZEOF(moo_obj_t) + get_payload_bytes(moo, oop);
 | 
			
		||||
 | 
			
		||||
		moo_pushtmp (moo, &oop);
 | 
			
		||||
		z = (moo_oop_t)moo_allocbytes (moo, total_bytes);
 | 
			
		||||
		z = (moo_oop_t)moo_allocbytes(moo, total_bytes);
 | 
			
		||||
		moo_poptmp(moo);
 | 
			
		||||
 | 
			
		||||
		MOO_MEMCPY (z, oop, total_bytes);
 | 
			
		||||
 | 
			
		||||
@ -1173,6 +1173,12 @@ moo_oop_association_t moo_getatdic (
 | 
			
		||||
	moo_oop_t     key
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
moo_oop_association_t moo_lookupdic_noseterr (
 | 
			
		||||
	moo_t*            moo,
 | 
			
		||||
	moo_oop_dic_t     dic,
 | 
			
		||||
	const moo_oocs_t* name
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
moo_oop_association_t moo_lookupdic (
 | 
			
		||||
	moo_t*            moo,
 | 
			
		||||
	moo_oop_dic_t     dic,
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user