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

ruby-changes:38928

From: nobu <ko1@a...>
Date: Wed, 24 Jun 2015 12:51:17 +0900 (JST)
Subject: [ruby-changes:38928] nobu:r51009 (trunk): string.c: rb_fstring_cstr

nobu	2015-06-24 12:50:56 +0900 (Wed, 24 Jun 2015)

  New Revision: 51009

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

  Log:
    string.c: rb_fstring_cstr
    
    * string.c (rb_fstring_cstr): new function to make a fstring from
      a string literal.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51008)
+++ ChangeLog	(revision 51009)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Jun 24 12:47:14 2015  Nobuyoshi Nakada  <nobu@r...>
+Wed Jun 24 12:49:11 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_fstring_cstr): new function to make a fstring from
+	  a string literal.
 
 	* internal.h (rb_fstring_lit): new macro to make a fstring from a
 	  string literal.
Index: string.c
===================================================================
--- string.c	(revision 51008)
+++ string.c	(revision 51009)
@@ -46,6 +46,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L46
 #undef rb_str_buf_cat2
 #undef rb_str_cat2
 #undef rb_str_cat_cstr
+#undef rb_fstring_cstr
 
 static VALUE rb_str_clear(VALUE str);
 
@@ -303,6 +304,12 @@ rb_fstring_new(const char *ptr, long len https://github.com/ruby/ruby/blob/trunk/string.c#L304
     return rb_fstring(setup_fake_str(&fake_str, ptr, len, ENCINDEX_US_ASCII));
 }
 
+VALUE
+rb_fstring_cstr(const char *ptr)
+{
+    return rb_fstring_new(ptr, strlen(ptr));
+}
+
 static int
 fstring_set_class_i(st_data_t key, st_data_t val, st_data_t arg)
 {
Index: internal.h
===================================================================
--- internal.h	(revision 51008)
+++ internal.h	(revision 51009)
@@ -1091,6 +1091,15 @@ VALUE rb_fstring(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1091
 VALUE rb_fstring_new(const char *ptr, long len);
 #define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
 #define rb_fstring_literal(str) rb_fstring_lit(str)
+VALUE rb_fstring_cstr(const char *str);
+#if defined(__GNUC__) && !defined(__PCC__)
+#define rb_fstring_cstr(str) __extension__ (	\
+{						\
+    (__builtin_constant_p(str)) ?		\
+	rb_fstring_new((str), (long)strlen(str)) : \
+	rb_fstring_cstr(str); \
+})
+#endif
 int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
 int rb_str_symname_p(VALUE);
 VALUE rb_str_quote_unprintable(VALUE);

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

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