@@ -369,41 +369,6 @@ RSTRING_LEN(VALUE str)
369369 return RSTRING (str)->len ;
370370}
371371
372- RBIMPL_WARNING_PUSH ()
373- #if RBIMPL_COMPILER_IS(Intel)
374- RBIMPL_WARNING_IGNORED (413 )
375- #endif
376-
377- RBIMPL_ATTR_PURE_UNLESS_DEBUG ()
378- RBIMPL_ATTR_ARTIFICIAL ()
379- /* *
380- * @private
381- *
382- * "Expands" an embedded string into an ordinal one. This is a function that
383- * returns aggregated type. The returned struct always has its `as.heap.len`
384- * an `as.heap.ptr` fields set appropriately.
385- *
386- * This is an implementation detail that 3rd parties should never bother.
387- */
388- static inline struct RString
389- rbimpl_rstring_getmem (VALUE str)
390- {
391- RBIMPL_ASSERT_TYPE (str, RUBY_T_STRING );
392-
393- if (RB_FL_ANY_RAW (str, RSTRING_NOEMBED )) {
394- return *RSTRING (str);
395- }
396- else {
397- /* Expecting compilers to optimize this on-stack struct away. */
398- struct RString retval = {RBASIC_INIT };
399- retval.len = RSTRING_LEN (str);
400- retval.as .heap .ptr = RSTRING (str)->as .embed .ary ;
401- return retval;
402- }
403- }
404-
405- RBIMPL_WARNING_POP ()
406-
407372RBIMPL_ATTR_ARTIFICIAL ()
408373/* *
409374 * Queries the contents pointer of the string.
@@ -415,7 +380,9 @@ RBIMPL_ATTR_ARTIFICIAL()
415380static inline char *
416381RSTRING_PTR (VALUE str)
417382{
418- char *ptr = rbimpl_rstring_getmem (str).as .heap .ptr ;
383+ char *ptr = RB_FL_TEST_RAW (str, RSTRING_NOEMBED ) ?
384+ RSTRING (str)->as .heap .ptr :
385+ RSTRING (str)->as .embed .ary ;
419386
420387 if (RUBY_DEBUG && RB_UNLIKELY (! ptr)) {
421388 /* :BEWARE: @shyouhei thinks that currently, there are rooms for this
@@ -441,14 +408,17 @@ RBIMPL_ATTR_ARTIFICIAL()
441408static inline char *
442409RSTRING_END (VALUE str)
443410{
444- struct RString buf = rbimpl_rstring_getmem (str);
411+ char *ptr = RB_FL_TEST_RAW (str, RSTRING_NOEMBED ) ?
412+ RSTRING (str)->as .heap .ptr :
413+ RSTRING (str)->as .embed .ary ;
414+ long len = RSTRING_LEN (str);
445415
446- if (RUBY_DEBUG && RB_UNLIKELY (! buf. as . heap . ptr )) {
416+ if (RUBY_DEBUG && RB_UNLIKELY (!ptr)) {
447417 /* Ditto. */
448418 rb_debug_rstring_null_ptr (" RSTRING_END" );
449419 }
450420
451- return &buf. as . heap . ptr [buf. len ];
421+ return &ptr[len];
452422}
453423
454424RBIMPL_ATTR_ARTIFICIAL ()
@@ -477,16 +447,7 @@ RSTRING_LENINT(VALUE str)
477447 * @param ptrvar Variable where its contents is stored.
478448 * @param lenvar Variable where its length is stored.
479449 */
480- #ifdef HAVE_STMT_AND_DECL_IN_EXPR
481- # define RSTRING_GETMEM (str, ptrvar, lenvar ) \
482- __extension__ ({ \
483- struct RString rbimpl_str = rbimpl_rstring_getmem (str); \
484- (ptrvar) = rbimpl_str.as .heap .ptr ; \
485- (lenvar) = rbimpl_str.len ; \
486- })
487- #else
488450# define RSTRING_GETMEM (str, ptrvar, lenvar ) \
489451 ((ptrvar) = RSTRING_PTR (str), \
490452 (lenvar) = RSTRING_LEN (str))
491- #endif /* HAVE_STMT_AND_DECL_IN_EXPR */
492453#endif /* RBIMPL_RSTRING_H */
0 commit comments