[前][次][番号順一覧][スレッド一覧]

ruby-changes:38665

From: tenderlove <ko1@a...>
Date: Wed, 3 Jun 2015 16:22:35 +0900 (JST)
Subject: [ruby-changes:38665] tenderlove:r50746 (trunk): * vm.c: eagerly allocate `loading_table`. This eliminates the need to

tenderlove	2015-06-03 16:21:37 +0900 (Wed, 03 Jun 2015)

  New Revision: 50746

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50746

  Log:
    * vm.c: eagerly allocate `loading_table`.  This eliminates the need to
      do NULL checks when looking up the `loading_table` hash.
      https://github.com/ruby/ruby/pull/918
    
    * load.c: remove various NULL checks

  Modified files:
    trunk/ChangeLog
    trunk/load.c
    trunk/vm.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50745)
+++ ChangeLog	(revision 50746)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun  3 16:17:21 2015  Aaron Patterson <tenderlove@r...>
+
+	* vm.c: eagerly allocate `loading_table`.  This eliminates the need to
+	  do NULL checks when looking up the `loading_table` hash.
+	  https://github.com/ruby/ruby/pull/918
+
+	* load.c: remove various NULL checks
+
 Wed Jun  3 11:47:15 2015  Koichi Sasada  <ko1@a...>
 
 	* method.h: change fileds order to gather frequent acces fields.
Index: load.c
===================================================================
--- load.c	(revision 50745)
+++ load.c	(revision 50746)
@@ -463,56 +463,54 @@ rb_feature_p(const char *feature, const https://github.com/ruby/ruby/blob/trunk/load.c#L463
     }
 
     loading_tbl = get_loading_table();
-    if (loading_tbl) {
-	f = 0;
-	if (!expanded) {
-	    struct loaded_feature_searching fs;
-	    fs.name = feature;
-	    fs.len = len;
-	    fs.type = type;
-	    fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
-	    fs.result = 0;
-	    st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
-	    if ((f = fs.result) != 0) {
-		if (fn) *fn = f;
-		goto loading;
-	    }
-	}
-	if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
-	    if (fn) *fn = (const char*)data;
-	  loading:
-	    if (!ext) return 'u';
-	    return !IS_RBEXT(ext) ? 's' : 'r';
-	}
-	else {
-	    VALUE bufstr;
-	    char *buf;
-	    static const char so_ext[][4] = {
-		".so", ".o",
-	    };
-
-	    if (ext && *ext) return 0;
-	    bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
-	    buf = RSTRING_PTR(bufstr);
-	    MEMCPY(buf, feature, char, len);
-	    for (i = 0; (e = loadable_ext[i]) != 0; i++) {
-		strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
-		if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
-		    rb_str_resize(bufstr, 0);
-		    if (fn) *fn = (const char*)data;
-		    return i ? 's' : 'r';
-		}
-	    }
-	    for (i = 0; i < numberof(so_ext); i++) {
-		strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
-		if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
-		    rb_str_resize(bufstr, 0);
-		    if (fn) *fn = (const char*)data;
-		    return 's';
-		}
+    f = 0;
+    if (!expanded) {
+	struct loaded_feature_searching fs;
+	fs.name = feature;
+	fs.len = len;
+	fs.type = type;
+	fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
+	fs.result = 0;
+	st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
+	if ((f = fs.result) != 0) {
+	    if (fn) *fn = f;
+	    goto loading;
+	}
+    }
+    if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
+	if (fn) *fn = (const char*)data;
+      loading:
+	if (!ext) return 'u';
+	return !IS_RBEXT(ext) ? 's' : 'r';
+    }
+    else {
+	VALUE bufstr;
+	char *buf;
+	static const char so_ext[][4] = {
+	    ".so", ".o",
+	};
+
+	if (ext && *ext) return 0;
+	bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
+	buf = RSTRING_PTR(bufstr);
+	MEMCPY(buf, feature, char, len);
+	for (i = 0; (e = loadable_ext[i]) != 0; i++) {
+	    strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
+	    if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
+		rb_str_resize(bufstr, 0);
+		if (fn) *fn = (const char*)data;
+		return i ? 's' : 'r';
+	    }
+	}
+	for (i = 0; i < numberof(so_ext); i++) {
+	    strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
+	    if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
+		rb_str_resize(bufstr, 0);
+		if (fn) *fn = (const char*)data;
+		return 's';
 	    }
-	    rb_str_resize(bufstr, 0);
 	}
+	rb_str_resize(bufstr, 0);
     }
     return 0;
 }
@@ -716,11 +714,7 @@ load_lock(const char *ftptr) https://github.com/ruby/ruby/blob/trunk/load.c#L714
     st_data_t data;
     st_table *loading_tbl = get_loading_table();
 
-    if (!loading_tbl || !st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
-	/* loading ruby library should be serialized. */
-	if (!loading_tbl) {
-	    GET_VM()->loading_table = loading_tbl = st_init_strtable();
-	}
+    if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
 	/* partial state */
 	ftptr = ruby_strdup(ftptr);
 	data = (st_data_t)rb_thread_shield_new();
@@ -1090,9 +1084,6 @@ ruby_init_ext(const char *name, void (*i https://github.com/ruby/ruby/blob/trunk/load.c#L1084
 
     if (rb_provided(name))
 	return;
-    if (!loading_tbl) {
-	GET_VM()->loading_table = loading_tbl = st_init_strtable();
-    }
     st_update(loading_tbl, (st_data_t)name, register_init_ext, (st_data_t)init);
 }
 
Index: vm.c
===================================================================
--- vm.c	(revision 50745)
+++ vm.c	(revision 50746)
@@ -2859,6 +2859,7 @@ Init_vm_objects(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L2859
 
     /* initialize mark object array, hash */
     vm->mark_object_ary = rb_ary_tmp_new(128);
+    vm->loading_table = st_init_strtable();
 }
 
 /* top self */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]