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

ruby-changes:37530

From: nobu <ko1@a...>
Date: Mon, 16 Feb 2015 12:58:38 +0900 (JST)
Subject: [ruby-changes:37530] nobu:r49611 (trunk): error.c: use static IDs

nobu	2015-02-16 12:58:28 +0900 (Mon, 16 Feb 2015)

  New Revision: 49611

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

  Log:
    error.c: use static IDs
    
    * error.c (Init_Exception): initialize static IDs first.

  Modified files:
    trunk/error.c
Index: error.c
===================================================================
--- error.c	(revision 49610)
+++ error.c	(revision 49611)
@@ -645,12 +645,15 @@ VALUE rb_eSystemCallError; https://github.com/ruby/ruby/blob/trunk/error.c#L645
 VALUE rb_mErrno;
 static VALUE rb_eNOERROR;
 
+static ID id_new, id_bt, id_bt_locations, id_cause, id_message, id_backtrace;
+static ID id_status, id_name, id_args, id_Errno, id_errno, id_i_path;
+
 #undef rb_exc_new_cstr
 
 VALUE
 rb_exc_new(VALUE etype, const char *ptr, long len)
 {
-    return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
+    return rb_funcall(etype, id_new, 1, rb_str_new(ptr, len));
 }
 
 VALUE
@@ -663,7 +666,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L666
 rb_exc_new_str(VALUE etype, VALUE str)
 {
     StringValue(str);
-    return rb_funcall(etype, rb_intern("new"), 1, str);
+    return rb_funcall(etype, id_new, 1, str);
 }
 
 /*
@@ -723,7 +726,7 @@ exc_exception(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/error.c#L726
 static VALUE
 exc_to_s(VALUE exc)
 {
-    VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
+    VALUE mesg = rb_attr_get(exc, idMesg);
 
     if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
     return rb_String(mesg);
@@ -742,7 +745,7 @@ exc_to_s(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L745
 static VALUE
 exc_message(VALUE exc)
 {
-    return rb_funcall(exc, rb_intern("to_s"), 0, 0);
+    return rb_funcall(exc, idTo_s, 0, 0);
 }
 
 /*
@@ -805,11 +808,9 @@ exc_inspect(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L808
 static VALUE
 exc_backtrace(VALUE exc)
 {
-    ID bt;
     VALUE obj;
 
-    CONST_ID(bt, "bt");
-    obj = rb_attr_get(exc, bt);
+    obj = rb_attr_get(exc, id_bt);
 
     if (rb_backtrace_p(obj)) {
 	obj = rb_backtrace_to_str_ary(obj);
@@ -832,11 +833,9 @@ exc_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L833
 static VALUE
 exc_backtrace_locations(VALUE exc)
 {
-    ID bt_locations;
     VALUE obj;
 
-    CONST_ID(bt_locations, "bt_locations");
-    obj = rb_attr_get(exc, bt_locations);
+    obj = rb_attr_get(exc, id_bt_locations);
     if (!NIL_P(obj)) {
 	obj = rb_backtrace_to_location_ary(obj);
     }
@@ -899,8 +898,6 @@ rb_exc_set_backtrace(VALUE exc, VALUE bt https://github.com/ruby/ruby/blob/trunk/error.c#L898
 VALUE
 exc_cause(VALUE exc)
 {
-    ID id_cause;
-    CONST_ID(id_cause, "cause");
     return rb_attr_get(exc, id_cause);
 }
 
@@ -929,9 +926,6 @@ exc_equal(VALUE exc, VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L926
 
     if (rb_obj_class(exc) != rb_obj_class(obj)) {
 	int status = 0;
-	ID id_message, id_backtrace;
-	CONST_ID(id_message, "message");
-	CONST_ID(id_backtrace, "backtrace");
 
 	obj = rb_protect(try_convert_to_exception, obj, &status);
 	if (status || obj == Qundef) {
@@ -1021,7 +1015,7 @@ exit_initialize(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/error.c#L1015
 static VALUE
 exit_status(VALUE exc)
 {
-    return rb_attr_get(exc, rb_intern("status"));
+    return rb_attr_get(exc, id_status);
 }
 
 
@@ -1035,7 +1029,7 @@ exit_status(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1029
 static VALUE
 exit_success_p(VALUE exc)
 {
-    VALUE status_val = rb_attr_get(exc, rb_intern("status"));
+    VALUE status_val = rb_attr_get(exc, id_status);
     int status;
 
     if (NIL_P(status_val))
@@ -1107,7 +1101,7 @@ name_err_initialize(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/error.c#L1101
 static VALUE
 name_err_name(VALUE self)
 {
-    return rb_attr_get(self, rb_intern("name"));
+    return rb_attr_get(self, id_name);
 }
 
 /*
@@ -1267,7 +1261,7 @@ name_err_mesg_load(VALUE klass, VALUE st https://github.com/ruby/ruby/blob/trunk/error.c#L1261
 static VALUE
 nometh_err_args(VALUE self)
 {
-    return rb_attr_get(self, rb_intern("args"));
+    return rb_attr_get(self, id_args);
 }
 
 void
@@ -1397,7 +1391,7 @@ syserr_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/error.c#L1391
     }
     else {
 	rb_scan_args(argc, argv, "02", &mesg, &func);
-	error = rb_const_get(klass, rb_intern("Errno"));
+	error = rb_const_get(klass, id_Errno);
     }
     if (!NIL_P(error)) err = strerror(NUM2INT(error));
     else err = "unknown error";
@@ -1427,7 +1421,7 @@ syserr_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/error.c#L1421
 static VALUE
 syserr_errno(VALUE self)
 {
-    return rb_attr_get(self, rb_intern("errno"));
+    return rb_attr_get(self, id_errno);
 }
 
 /*
@@ -1442,20 +1436,17 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L1436
 syserr_eqq(VALUE self, VALUE exc)
 {
     VALUE num, e;
-    ID en;
-
-    CONST_ID(en, "errno");
 
     if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
-	if (!rb_respond_to(exc, en)) return Qfalse;
+	if (!rb_respond_to(exc, id_errno)) return Qfalse;
     }
     else if (self == rb_eSystemCallError) return Qtrue;
 
-    num = rb_attr_get(exc, rb_intern("errno"));
+    num = rb_attr_get(exc, id_errno);
     if (NIL_P(num)) {
-	num = rb_funcall(exc, en, 0, 0);
+	num = rb_funcall(exc, id_errno, 0, 0);
     }
-    e = rb_const_get(self, rb_intern("Errno"));
+    e = rb_const_get(self, id_Errno);
     if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
 	return Qtrue;
     return Qfalse;
@@ -1915,6 +1906,19 @@ Init_Exception(void) https://github.com/ruby/ruby/blob/trunk/error.c#L1906
     rb_mErrno = rb_define_module("Errno");
 
     rb_define_global_function("warn", rb_warn_m, -1);
+
+    id_new = rb_intern_const("new");
+    id_bt = rb_intern_const("bt");
+    id_bt_locations = rb_intern_const("bt_locations");
+    id_cause = rb_intern_const("cause");
+    id_message = rb_intern_const("message");
+    id_backtrace = rb_intern_const("backtrace");
+    id_status = rb_intern_const("status");
+    id_name = rb_intern_const("name");
+    id_args = rb_intern_const("args");
+    id_Errno = rb_intern_const("Errno");
+    id_errno = rb_intern_const("errno");
+    id_i_path = rb_intern_const("@path");
 }
 
 void
@@ -1948,7 +1952,7 @@ static void https://github.com/ruby/ruby/blob/trunk/error.c#L1952
 raise_loaderror(VALUE path, VALUE mesg)
 {
     VALUE err = rb_exc_new3(rb_eLoadError, mesg);
-    rb_ivar_set(err, rb_intern("@path"), path);
+    rb_ivar_set(err, id_i_path, path);
     rb_exc_raise(err);
 }
 

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

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