[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 SYMBOL_LIT(str) ID2SYM(rb_intern_const(str ""))
|
||||
|
||||
#ifdef HAVE_RB_DEPRECATE_CONSTANT
|
||||
void rb_deprecate_constant(VALUE mod, const char *name);
|
||||
#else
|
||||
@ -697,7 +699,7 @@ rbconfig(void)
|
||||
{
|
||||
VALUE config;
|
||||
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);
|
||||
return config;
|
||||
}
|
||||
@ -823,12 +825,12 @@ etc_uname(VALUE obj)
|
||||
sysname = "Windows";
|
||||
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);
|
||||
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,
|
||||
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
|
||||
# define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)
|
||||
@ -842,7 +844,7 @@ etc_uname(VALUE obj)
|
||||
}
|
||||
ALLOCV_END(vbuf);
|
||||
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
|
||||
# define PROCESSOR_ARCHITECTURE_AMD64 9
|
||||
@ -866,7 +868,7 @@ etc_uname(VALUE obj)
|
||||
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
|
||||
struct utsname u;
|
||||
int ret;
|
||||
@ -877,11 +879,11 @@ etc_uname(VALUE obj)
|
||||
rb_sys_fail("uname");
|
||||
|
||||
result = rb_hash_new();
|
||||
rb_hash_aset(result, ID2SYM(rb_intern("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, ID2SYM(rb_intern("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, ID2SYM(rb_intern("machine")), rb_str_new_cstr(u.machine));
|
||||
rb_hash_aset(result, SYMBOL_LIT("sysname"), rb_str_new_cstr(u.sysname));
|
||||
rb_hash_aset(result, SYMBOL_LIT("nodename"), rb_str_new_cstr(u.nodename));
|
||||
rb_hash_aset(result, SYMBOL_LIT("release"), rb_str_new_cstr(u.release));
|
||||
rb_hash_aset(result, SYMBOL_LIT("version"), rb_str_new_cstr(u.version));
|
||||
rb_hash_aset(result, SYMBOL_LIT("machine"), rb_str_new_cstr(u.machine));
|
||||
#endif
|
||||
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user