ruby-changes:27592
From: nobu <ko1@a...>
Date: Sat, 9 Mar 2013 08:37:24 +0900 (JST)
Subject: [ruby-changes:27592] nobu:r39644 (trunk): load.c: reduce indexes arrays
nobu 2013-03-09 08:37:02 +0900 (Sat, 09 Mar 2013) New Revision: 39644 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39644 Log: load.c: reduce indexes arrays * load.c (features_index_add_single, rb_feature_p): store single index as Fixnum to reduce the number of arrays for the indexes. based on the patch by tmm1 (Aman Gupta) in [ruby-core:53216] [Bug #8048]. Modified files: trunk/ChangeLog trunk/load.c Index: ChangeLog =================================================================== --- ChangeLog (revision 39643) +++ ChangeLog (revision 39644) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Mar 9 08:36:58 2013 Nobuyoshi Nakada <nobu@r...> + + * load.c (features_index_add_single, rb_feature_p): store single index + as Fixnum to reduce the number of arrays for the indexes. based on + the patch by tmm1 (Aman Gupta) in [ruby-core:53216] [Bug #8048]. + Sat Mar 9 00:25:57 2013 Nobuyoshi Nakada <nobu@r...> * marshal.c (r_object0): load prepended objects. treat the class of Index: load.c =================================================================== --- load.c (revision 39643) +++ load.c (revision 39644) @@ -11,6 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/load.c#L11 VALUE ruby_dln_librefs; +#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) + #define IS_RBEXT(e) (strcmp((e), ".rb") == 0) #define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0) #ifdef DLEXT2 @@ -186,11 +188,23 @@ features_index_add_single(VALUE short_fe https://github.com/ruby/ruby/blob/trunk/load.c#L188 { VALUE features_index, this_feature_index; features_index = get_loaded_features_index_raw(); - if ((this_feature_index = rb_hash_lookup(features_index, short_feature)) == Qnil) { - this_feature_index = rb_ary_new(); + this_feature_index = rb_hash_lookup(features_index, short_feature); + + if (NIL_P(this_feature_index)) { + rb_hash_aset(features_index, short_feature, offset); + } + else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) { + VALUE feature_indexes[2]; + feature_indexes[0] = this_feature_index; + feature_indexes[1] = offset; + this_feature_index = rb_ary_tmp_new(numberof(feature_indexes)); + rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes)); rb_hash_aset(features_index, short_feature, this_feature_index); } - rb_ary_push(this_feature_index, offset); + else { + Check_Type(this_feature_index, T_ARRAY); + rb_ary_push(this_feature_index, offset); + } } /* Add to the loaded-features index all the required entries for @@ -392,8 +406,19 @@ rb_feature_p(const char *feature, const https://github.com/ruby/ruby/blob/trunk/load.c#L406 or ends in '/'. This includes both match forms above, as well as any distractors, so we may ignore all other entries in `features`. */ - for (i = 0; this_feature_index != Qnil && i < RARRAY_LEN(this_feature_index); i++) { - long index = FIX2LONG(rb_ary_entry(this_feature_index, i)); + for (i = 0; !NIL_P(this_feature_index); i++) { + VALUE entry; + long index; + if (RB_TYPE_P(this_feature_index, T_ARRAY)) { + if (i >= RARRAY_LEN(this_feature_index)) break; + entry = RARRAY_PTR(this_feature_index)[i]; + } + else { + if (i > 0) break; + entry = this_feature_index; + } + index = FIX2LONG(entry); + v = RARRAY_PTR(features)[index]; f = StringValuePtr(v); if ((n = RSTRING_LEN(v)) < len) continue; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/