Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* load.c (loaded_feature_path): cut nonsence loop execution to fix

	  performance bug.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 9ce69e7cef1272c86a93eeb9a1888fe6d2a94704 1 parent 867fa45
Masaya TARUI authored May 31, 2011

Showing 2 changed files with 20 additions and 4 deletions. Show diff stats Hide diff stats

  1. 5  ChangeLog
  2. 19  load.c
5  ChangeLog
... ...
@@ -1,3 +1,8 @@
  1
+Wed Jun  1 06:43:13 2011  Masaya Tarui  <tarui@ruby-lang.org>
  2
+
  3
+	* load.c (loaded_feature_path): cut nonsence loop execution to fix
  4
+	  performance bug.
  5
+
1 6
 Wed Jun  1 01:16:02 2011  Nobuyoshi Nakada  <nobu@ruby-lang.org>
2 7
 
3 8
 	* class.c (rb_mix_module): implement Module#mix.
19  load.c
@@ -73,16 +73,27 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len,
73 73
 		    int type, VALUE load_path)
74 74
 {
75 75
     long i;
76  
-
  76
+    long plen;
  77
+    const char *e;
  78
+
  79
+    if(vlen < len) return 0;
  80
+    if (!strncmp(name+(vlen-len),feature,len)){
  81
+	plen = vlen - len - 1;
  82
+    } else {
  83
+	for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
  84
+	if (*e!='.' ||
  85
+	    e-name < len ||
  86
+	    strncmp(e-len,feature,len) )
  87
+	    return 0;
  88
+	plen = e - name - len - 1;
  89
+    }
77 90
     for (i = 0; i < RARRAY_LEN(load_path); ++i) {
78 91
 	VALUE p = RARRAY_PTR(load_path)[i];
79 92
 	const char *s = StringValuePtr(p);
80 93
 	long n = RSTRING_LEN(p);
81 94
 
82  
-	if (vlen < n + len + 1) continue;
  95
+	if (n != plen ) continue;
83 96
 	if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
84  
-	if (strncmp(name + n + 1, feature, len)) continue;
85  
-	if (name[n+len+1] && name[n+len+1] != '.') continue;
86 97
 	switch (type) {
87 98
 	  case 's':
88 99
 	    if (IS_DLEXT(&name[n+len+1])) return p;

0 notes on commit 9ce69e7

Please sign in to comment.
Something went wrong with that request. Please try again.