diff --git a/hash.c b/hash.c index 126fd41dc8..b8acbc8491 100644 --- a/hash.c +++ b/hash.c @@ -2548,13 +2548,31 @@ env_keys(void) * * An Enumerator is returned if no block is given. */ +static VALUE +rb_env_size(VALUE ehash) +{ + char **env; + long cnt = 0; + + rb_secure(4); + + env = GET_ENVIRON(environ); + for (; *env ; ++env) { + if (strchr(*env, '=')) { + cnt++; + } + } + FREE_ENVIRON(environ); + return LONG2FIX(cnt); +} + static VALUE env_each_key(VALUE ehash) { VALUE keys; long i; - RETURN_ENUMERATOR(ehash, 0, 0); + RETURN_SIZED_ENUMERATOR(ehash, 0, 0, rb_env_size); keys = env_keys(); /* rb_secure(4); */ for (i=0; i