[ruby/etc] Prefer rb_intern_const
over rb_intern
for literal strings
https://github.com/ruby/etc/commit/53362d891c
This commit is contained in:
parent
41a9460227
commit
577e6a3e19
@ -58,6 +58,8 @@ RUBY_EXTERN char *getlogin(void);
|
|||||||
|
|
||||||
#define RUBY_ETC_VERSION "1.4.4"
|
#define RUBY_ETC_VERSION "1.4.4"
|
||||||
|
|
||||||
|
#define SYMBOL_LIT(str) ID2SYM(rb_intern_const(str ""))
|
||||||
|
|
||||||
#ifdef HAVE_RB_DEPRECATE_CONSTANT
|
#ifdef HAVE_RB_DEPRECATE_CONSTANT
|
||||||
void rb_deprecate_constant(VALUE mod, const char *name);
|
void rb_deprecate_constant(VALUE mod, const char *name);
|
||||||
#else
|
#else
|
||||||
@ -697,7 +699,7 @@ rbconfig(void)
|
|||||||
{
|
{
|
||||||
VALUE config;
|
VALUE config;
|
||||||
rb_require("rbconfig");
|
rb_require("rbconfig");
|
||||||
config = rb_const_get(rb_path2class("RbConfig"), rb_intern("CONFIG"));
|
config = rb_const_get(rb_path2class("RbConfig"), rb_intern_const("CONFIG"));
|
||||||
Check_Type(config, T_HASH);
|
Check_Type(config, T_HASH);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@ -823,12 +825,12 @@ etc_uname(VALUE obj)
|
|||||||
sysname = "Windows";
|
sysname = "Windows";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(sysname));
|
rb_hash_aset(result, SYMBOL_LIT("sysname"), rb_str_new_cstr(sysname));
|
||||||
release = rb_sprintf("%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
|
release = rb_sprintf("%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("release")), release);
|
rb_hash_aset(result, SYMBOL_LIT("release"), release);
|
||||||
version = rb_sprintf("%s Version %"PRIsVALUE": %"PRIsVALUE, sysname, release,
|
version = rb_sprintf("%s Version %"PRIsVALUE": %"PRIsVALUE, sysname, release,
|
||||||
rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));
|
rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("version")), version);
|
rb_hash_aset(result, SYMBOL_LIT("version"), version);
|
||||||
|
|
||||||
# if defined _MSC_VER && _MSC_VER < 1300
|
# if defined _MSC_VER && _MSC_VER < 1300
|
||||||
# define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)
|
# define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)
|
||||||
@ -842,7 +844,7 @@ etc_uname(VALUE obj)
|
|||||||
}
|
}
|
||||||
ALLOCV_END(vbuf);
|
ALLOCV_END(vbuf);
|
||||||
if (NIL_P(nodename)) nodename = rb_str_new(0, 0);
|
if (NIL_P(nodename)) nodename = rb_str_new(0, 0);
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), nodename);
|
rb_hash_aset(result, SYMBOL_LIT("nodename"), nodename);
|
||||||
|
|
||||||
# ifndef PROCESSOR_ARCHITECTURE_AMD64
|
# ifndef PROCESSOR_ARCHITECTURE_AMD64
|
||||||
# define PROCESSOR_ARCHITECTURE_AMD64 9
|
# define PROCESSOR_ARCHITECTURE_AMD64 9
|
||||||
@ -866,7 +868,7 @@ etc_uname(VALUE obj)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(mach));
|
rb_hash_aset(result, SYMBOL_LIT("machine"), rb_str_new_cstr(mach));
|
||||||
#else
|
#else
|
||||||
struct utsname u;
|
struct utsname u;
|
||||||
int ret;
|
int ret;
|
||||||
@ -877,11 +879,11 @@ etc_uname(VALUE obj)
|
|||||||
rb_sys_fail("uname");
|
rb_sys_fail("uname");
|
||||||
|
|
||||||
result = rb_hash_new();
|
result = rb_hash_new();
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(u.sysname));
|
rb_hash_aset(result, SYMBOL_LIT("sysname"), rb_str_new_cstr(u.sysname));
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), rb_str_new_cstr(u.nodename));
|
rb_hash_aset(result, SYMBOL_LIT("nodename"), rb_str_new_cstr(u.nodename));
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("release")), rb_str_new_cstr(u.release));
|
rb_hash_aset(result, SYMBOL_LIT("release"), rb_str_new_cstr(u.release));
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("version")), rb_str_new_cstr(u.version));
|
rb_hash_aset(result, SYMBOL_LIT("version"), rb_str_new_cstr(u.version));
|
||||||
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(u.machine));
|
rb_hash_aset(result, SYMBOL_LIT("machine"), rb_str_new_cstr(u.machine));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user