Skip to content

Commit 577e6a3

Browse files
nobumatzbot
authored andcommitted
[ruby/etc] Prefer rb_intern_const over rb_intern for literal strings
ruby/etc@53362d891c
1 parent 41a9460 commit 577e6a3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

ext/etc/etc.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ RUBY_EXTERN char *getlogin(void);
5858

5959
#define RUBY_ETC_VERSION "1.4.4"
6060

61+
#define SYMBOL_LIT(str) ID2SYM(rb_intern_const(str ""))
62+
6163
#ifdef HAVE_RB_DEPRECATE_CONSTANT
6264
void rb_deprecate_constant(VALUE mod, const char *name);
6365
#else
@@ -697,7 +699,7 @@ rbconfig(void)
697699
{
698700
VALUE config;
699701
rb_require("rbconfig");
700-
config = rb_const_get(rb_path2class("RbConfig"), rb_intern("CONFIG"));
702+
config = rb_const_get(rb_path2class("RbConfig"), rb_intern_const("CONFIG"));
701703
Check_Type(config, T_HASH);
702704
return config;
703705
}
@@ -823,12 +825,12 @@ etc_uname(VALUE obj)
823825
sysname = "Windows";
824826
break;
825827
}
826-
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(sysname));
828+
rb_hash_aset(result, SYMBOL_LIT("sysname"), rb_str_new_cstr(sysname));
827829
release = rb_sprintf("%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
828-
rb_hash_aset(result, ID2SYM(rb_intern("release")), release);
830+
rb_hash_aset(result, SYMBOL_LIT("release"), release);
829831
version = rb_sprintf("%s Version %"PRIsVALUE": %"PRIsVALUE, sysname, release,
830832
rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));
831-
rb_hash_aset(result, ID2SYM(rb_intern("version")), version);
833+
rb_hash_aset(result, SYMBOL_LIT("version"), version);
832834

833835
# if defined _MSC_VER && _MSC_VER < 1300
834836
# define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)
@@ -842,7 +844,7 @@ etc_uname(VALUE obj)
842844
}
843845
ALLOCV_END(vbuf);
844846
if (NIL_P(nodename)) nodename = rb_str_new(0, 0);
845-
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), nodename);
847+
rb_hash_aset(result, SYMBOL_LIT("nodename"), nodename);
846848

847849
# ifndef PROCESSOR_ARCHITECTURE_AMD64
848850
# define PROCESSOR_ARCHITECTURE_AMD64 9
@@ -866,7 +868,7 @@ etc_uname(VALUE obj)
866868
break;
867869
}
868870

869-
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(mach));
871+
rb_hash_aset(result, SYMBOL_LIT("machine"), rb_str_new_cstr(mach));
870872
#else
871873
struct utsname u;
872874
int ret;
@@ -877,11 +879,11 @@ etc_uname(VALUE obj)
877879
rb_sys_fail("uname");
878880

879881
result = rb_hash_new();
880-
rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(u.sysname));
881-
rb_hash_aset(result, ID2SYM(rb_intern("nodename")), rb_str_new_cstr(u.nodename));
882-
rb_hash_aset(result, ID2SYM(rb_intern("release")), rb_str_new_cstr(u.release));
883-
rb_hash_aset(result, ID2SYM(rb_intern("version")), rb_str_new_cstr(u.version));
884-
rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(u.machine));
882+
rb_hash_aset(result, SYMBOL_LIT("sysname"), rb_str_new_cstr(u.sysname));
883+
rb_hash_aset(result, SYMBOL_LIT("nodename"), rb_str_new_cstr(u.nodename));
884+
rb_hash_aset(result, SYMBOL_LIT("release"), rb_str_new_cstr(u.release));
885+
rb_hash_aset(result, SYMBOL_LIT("version"), rb_str_new_cstr(u.version));
886+
rb_hash_aset(result, SYMBOL_LIT("machine"), rb_str_new_cstr(u.machine));
885887
#endif
886888

887889
return result;

0 commit comments

Comments
 (0)