From: Florian Ragwitz Date: Mon, 9 Mar 2009 22:30:24 +0000 (+0100) Subject: Don't iterate over all package symbols only to check if there is at least one method. X-Git-Tag: 0.78_01~80 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82a64f20a239bacc0a7f104b85db6a3e40c82c28;p=gitmo%2FClass-MOP.git Don't iterate over all package symbols only to check if there is at least one method. --- diff --git a/MOP.xs b/MOP.xs index 5695fc3..7d82305 100644 --- a/MOP.xs +++ b/MOP.xs @@ -225,6 +225,14 @@ get_package_symbols(HV *stash, type_filter_t filter, get_package_symbols_cb_t cb } static bool +find_method (const char *key, STRLEN keylen, SV *val, void *ud) +{ + bool *found_method = (bool *)ud; + *found_method = TRUE; + return FALSE; +} + +static bool collect_all_symbols (const char *key, STRLEN keylen, SV *val, void *ud) { HV *hash = (HV *)ud; @@ -369,7 +377,7 @@ is_class_loaded(klass=&PL_sv_undef) SV *klass PREINIT: HV *stash; - HV *symbols; + bool found_method = FALSE; PPCODE: if (!SvPOK(klass) || !SvCUR(klass)) { XSRETURN_NO; @@ -404,13 +412,11 @@ is_class_loaded(klass=&PL_sv_undef) } } - symbols = get_all_package_symbols(stash, TYPE_FILTER_CODE); - if (HvKEYS(symbols) > 0) { - SvREFCNT_dec((SV *)symbols); + get_package_symbols(stash, TYPE_FILTER_CODE, find_method, &found_method); + if (found_method) { XSRETURN_YES; } - SvREFCNT_dec((SV *)symbols); XSRETURN_NO; MODULE = Class::MOP PACKAGE = Class::MOP::Package