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

ruby-changes:37502

From: nobu <ko1@a...>
Date: Fri, 13 Feb 2015 16:07:49 +0900 (JST)
Subject: [ruby-changes:37502] nobu:r49583 (trunk): util.c: hexdigit

nobu	2015-02-13 16:07:39 +0900 (Fri, 13 Feb 2015)

  New Revision: 49583

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

  Log:
    util.c: hexdigit
    
    * util.c (hexdigit): extract identical constants.

  Modified files:
    trunk/internal.h
    trunk/pack.c
    trunk/sprintf.c
    trunk/util.c
    trunk/vsnprintf.c
Index: vsnprintf.c
===================================================================
--- vsnprintf.c	(revision 49582)
+++ vsnprintf.c	(revision 49583)
@@ -510,6 +510,12 @@ static int exponent(char *, int, int); https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L510
 
 #endif /* FLOATING_POINT */
 
+#ifndef lower_hexdigits
+# define lower_hexdigits "0123456789abcdef"
+#endif
+#ifndef upper_hexdigits
+# define upper_hexdigits "0123456789ABCDEF"
+#endif
 
 /*
  * Flags used during conversion.
@@ -993,7 +999,7 @@ fp_begin:		_double = va_arg(ap, double); https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L999
 #endif /* _HAVE_SANE_QUAD_ */
 #endif
 			base = 16;
-			xdigs = "0123456789abcdef";
+			xdigs = lower_hexdigits;
 			ch = 'x';
 			goto nosign;
 		case 's':
@@ -1031,10 +1037,10 @@ fp_begin:		_double = va_arg(ap, double); https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L1037
 			base = 10;
 			goto nosign;
 		case 'X':
-			xdigs = "0123456789ABCDEF";
+			xdigs = upper_hexdigits;
 			goto hex;
 		case 'x':
-			xdigs = "0123456789abcdef";
+			xdigs = lower_hexdigits;
 hex:
 #ifdef _HAVE_SANE_QUAD_
 			if (flags & QUADINT)
@@ -1251,7 +1257,7 @@ cvt(double value, int ndigits, int flags https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L1257
 	}
 	if (ch == 'a' || ch =='A') {
 	    digits = BSD__hdtoa(value,
-		    ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF",
+		    ch == 'a' ? lower_hexdigits : upper_hexdigits,
 		    ndigits, decpt, &dsgn, &rve);
 	}
 	else {
Index: pack.c
===================================================================
--- pack.c	(revision 49582)
+++ pack.c	(revision 49583)
@@ -1204,7 +1204,7 @@ infected_str_new(const char *ptr, long l https://github.com/ruby/ruby/blob/trunk/pack.c#L1204
 static VALUE
 pack_unpack(VALUE str, VALUE fmt)
 {
-    static const char hexdigits[] = "0123456789abcdef";
+#define hexdigits ruby_hexdigits
     char *s, *send;
     char *p, *pend;
     VALUE ary;
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 49582)
+++ sprintf.c	(revision 49583)
@@ -1252,6 +1252,8 @@ fmt_setup(char *buf, size_t size, int c, https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1252
 #ifdef RUBY_PRI_VALUE_MARK
 # define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
 #endif
+#define lower_hexdigits (ruby_hexdigits+0)
+#define upper_hexdigits (ruby_hexdigits+16)
 #include "vsnprintf.c"
 
 typedef struct {
Index: util.c
===================================================================
--- util.c	(revision 49582)
+++ util.c	(revision 49583)
@@ -23,6 +23,9 @@ https://github.com/ruby/ruby/blob/trunk/util.c#L23
 
 #include "ruby/util.h"
 
+const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF";
+#define hexdigit ruby_hexdigits
+
 unsigned long
 ruby_scan_oct(const char *start, size_t len, size_t *retlen)
 {
@@ -40,7 +43,6 @@ ruby_scan_oct(const char *start, size_t https://github.com/ruby/ruby/blob/trunk/util.c#L43
 unsigned long
 ruby_scan_hex(const char *start, size_t len, size_t *retlen)
 {
-    static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
     register const char *s = start;
     register unsigned long retval = 0;
     const char *tmp;
@@ -1993,7 +1995,6 @@ ruby_strtod(const char *s00, char **se) https://github.com/ruby/ruby/blob/trunk/util.c#L1995
 break2:
     if (*s == '0') {
 	if (s[1] == 'x' || s[1] == 'X') {
-	    static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
 	    s0 = ++s;
 	    adj = 0;
 	    aadj = 1.0;
Index: internal.h
===================================================================
--- internal.h	(revision 49582)
+++ internal.h	(revision 49583)
@@ -1157,6 +1157,7 @@ VALUE rb_setup_fake_str(struct RString * https://github.com/ruby/ruby/blob/trunk/internal.h#L1157
 
 /* util.c (export) */
 extern const signed char ruby_digit36_to_number_table[];
+extern const char ruby_hexdigits[];
 
 /* variable.c (export) */
 void rb_gc_mark_global_tbl(void);

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

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