Skip to content

Commit

Permalink
Remove RSTRING_EMBED_LEN
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jun 5, 2023
1 parent 4aaffaa commit 3cc3b9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
36 changes: 4 additions & 32 deletions include/ruby/internal/core/rstring.h
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -409,29 +396,14 @@ 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;
}
}

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.
Expand Down
8 changes: 4 additions & 4 deletions string.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3cc3b9b

Please sign in to comment.