From 3cc3b9bcc7568f3bdac07d1b42f72b03e03029af Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 5 Jun 2023 15:29:08 -0400 Subject: [PATCH] Remove RSTRING_EMBED_LEN --- include/ruby/internal/core/rstring.h | 36 ++++------------------------ string.c | 8 +++---- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/include/ruby/internal/core/rstring.h b/include/ruby/internal/core/rstring.h index 6cc53244e4db84..a03ad5b2ec9ed0 100644 --- a/include/ruby/internal/core/rstring.h +++ b/include/ruby/internal/core/rstring.h @@ -43,7 +43,6 @@ /** @cond INTERNAL_MACRO */ #define RSTRING_NOEMBED RSTRING_NOEMBED #define RSTRING_FSTR RSTRING_FSTR -#define RSTRING_EMBED_LEN RSTRING_EMBED_LEN #define RSTRING_LEN RSTRING_LEN #define RSTRING_LENINT RSTRING_LENINT #define RSTRING_PTR RSTRING_PTR @@ -362,24 +361,12 @@ RBIMPL_ATTR_ARTIFICIAL() * * @param[in] str String in question. * @return Its length, in bytes. - * @pre `str` must be an instance of ::RString, and must has its - * ::RSTRING_NOEMBED flag off. - * - * @internal - * - * This was a macro before. It was inevitable to be public, since macros are - * global constructs. But should it be forever? Now that it is a function, - * @shyouhei thinks it could just be eliminated, hidden into implementation - * details. + * @pre `str` must be an instance of ::RString. */ static inline long -RSTRING_EMBED_LEN(VALUE str) // TODO: delete? +RSTRING_LEN(VALUE str) { - RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING); - RBIMPL_ASSERT_OR_ASSUME(! RB_FL_ANY_RAW(str, RSTRING_NOEMBED)); - - long f = RSTRING(str)->len; - return f; + return RSTRING(str)->len; } RBIMPL_WARNING_PUSH() @@ -409,7 +396,7 @@ rbimpl_rstring_getmem(VALUE str) else { /* Expecting compilers to optimize this on-stack struct away. */ struct RString retval; - retval.len = RSTRING_EMBED_LEN(str); + retval.len = RSTRING_LEN(str); retval.as.heap.ptr = RSTRING(str)->as.embed.ary; return retval; } @@ -417,21 +404,6 @@ rbimpl_rstring_getmem(VALUE str) RBIMPL_WARNING_POP() -RBIMPL_ATTR_PURE_UNLESS_DEBUG() -RBIMPL_ATTR_ARTIFICIAL() -/** - * Queries the length of the string. - * - * @param[in] str String in question. - * @return Its length, in bytes. - * @pre `str` must be an instance of ::RString. - */ -static inline long -RSTRING_LEN(VALUE str) -{ - return rbimpl_rstring_getmem(str).len; -} - RBIMPL_ATTR_ARTIFICIAL() /** * Queries the contents pointer of the string. diff --git a/string.c b/string.c index 8dc2bcd74328df..a7d05693f1514a 100644 --- a/string.c +++ b/string.c @@ -1700,7 +1700,7 @@ str_duplicate_setup(VALUE klass, VALUE str, VALUE dup) VALUE flags = FL_TEST_RAW(str, flag_mask); int encidx = 0; if (STR_EMBED_P(str)) { - long len = RSTRING_EMBED_LEN(str); + long len = RSTRING_LEN(str); assert(STR_EMBED_P(dup)); assert(str_embed_capa(dup) >= len + 1); @@ -1743,7 +1743,7 @@ ec_str_duplicate(struct rb_execution_context_struct *ec, VALUE klass, VALUE str) dup = ec_str_alloc_heap(ec, klass); } else { - dup = ec_str_alloc_embed(ec, klass, RSTRING_EMBED_LEN(str) + TERM_LEN(str)); + dup = ec_str_alloc_embed(ec, klass, RSTRING_LEN(str) + TERM_LEN(str)); } return str_duplicate_setup(klass, str, dup); @@ -1757,7 +1757,7 @@ str_duplicate(VALUE klass, VALUE str) dup = str_alloc_heap(klass); } else { - dup = str_alloc_embed(klass, RSTRING_EMBED_LEN(str) + TERM_LEN(str)); + dup = str_alloc_embed(klass, RSTRING_LEN(str) + TERM_LEN(str)); } return str_duplicate_setup(klass, str, dup); @@ -10714,7 +10714,7 @@ rb_str_b(VALUE str) str2 = str_alloc_heap(rb_cString); } else { - str2 = str_alloc_embed(rb_cString, RSTRING_EMBED_LEN(str) + TERM_LEN(str)); + str2 = str_alloc_embed(rb_cString, RSTRING_LEN(str) + TERM_LEN(str)); } str_replace_shared_without_enc(str2, str);