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

ruby-changes:43741

From: nobu <ko1@a...>
Date: Fri, 5 Aug 2016 17:04:11 +0900 (JST)
Subject: [ruby-changes:43741] nobu:r55813 (trunk): hash.c: call w32_getenv pointer

nobu	2016-08-05 17:04:04 +0900 (Fri, 05 Aug 2016)

  New Revision: 55813

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

  Log:
    hash.c: call w32_getenv pointer
    
    * hash.c (w32_getenv): call rb_w32_getenv and rb_w32_ugetenv via
      this pointer without further comparisons.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55812)
+++ ChangeLog	(revision 55813)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug  5 17:04:02 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (w32_getenv): call rb_w32_getenv and rb_w32_ugetenv via
+	  this pointer without further comparisons.
+
 Thu Aug  4 11:54:30 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (env_assoc): the encoding of the value should be the
Index: hash.c
===================================================================
--- hash.c	(revision 55812)
+++ hash.c	(revision 55813)
@@ -2896,17 +2896,21 @@ static char **my_environ; https://github.com/ruby/ruby/blob/trunk/hash.c#L2896
 #undef environ
 #define environ my_environ
 #undef getenv
-static inline char *
-w32_getenv(const char *name)
+static char *(*w32_getenv)(const char*);
+static char *
+w32_getenv_unknown(const char *name)
 {
-    static int binary = -1;
-    static int locale = -1;
-    if (binary < 0) {
-	binary = rb_ascii8bit_encindex();
-	locale = rb_locale_encindex();
+    char *(*func)(const char*);
+    if (rb_locale_encindex() == rb_ascii8bit_encindex()) {
+	func = rb_w32_getenv;
     }
-    return locale == binary ? rb_w32_getenv(name) : rb_w32_ugetenv(name);
+    else {
+	func = rb_w32_ugetenv;
+    }
+    /* atomic assignment in flat memory model */
+    return (w32_getenv = func)(name);
 }
+static char *(*w32_getenv)(const char*) = w32_getenv_unknown;
 #define getenv(n) w32_getenv(n)
 #elif defined(__APPLE__)
 #undef environ

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

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