From d3199656be297d33696418f8730577fd30735445 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 24 Jun 2015 03:50:56 +0000 Subject: [PATCH] string.c: rb_fstring_cstr * string.c (rb_fstring_cstr): new function to make a fstring from a string literal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- internal.h | 9 +++++++++ string.c | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a52222610d..da800f3a4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Wed Jun 24 12:47:14 2015 Nobuyoshi Nakada +Wed Jun 24 12:49:11 2015 Nobuyoshi Nakada + + * 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. diff --git a/internal.h b/internal.h index 7b085cee31..32ad346e07 100644 --- a/internal.h +++ b/internal.h @@ -1091,6 +1091,15 @@ VALUE rb_fstring(VALUE); 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); diff --git a/string.c b/string.c index 4d2944ccd4..1a962153a1 100644 --- a/string.c +++ b/string.c @@ -46,6 +46,7 @@ #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) 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) {