mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Feature #18239] Add struct for embedded strings
This commit is contained in:
parent
09fa773e04
commit
46b66eb9e8
Notes:
git
2021-10-26 02:26:50 +09:00
2 changed files with 22 additions and 21 deletions
|
@ -270,15 +270,16 @@ struct RString {
|
|||
VALUE shared;
|
||||
} aux;
|
||||
} heap;
|
||||
|
||||
/**
|
||||
* Embedded contents. When a string is short enough, it uses this area
|
||||
* to store the contents themselves. This was impractical in the 20th
|
||||
* century, but these days 64 bit machines can typically hold 48 bytes
|
||||
* here. Could be sufficiently large. In this case the length is
|
||||
* encoded into the flags.
|
||||
*/
|
||||
char ary[RSTRING_EMBED_LEN_MAX + 1];
|
||||
struct {
|
||||
/**
|
||||
* Embedded contents. When a string is short enough, it uses this area
|
||||
* to store the contents themselves. This was impractical in the 20th
|
||||
* century, but these days 64 bit machines can typically hold 48 bytes
|
||||
* here. Could be sufficiently large. In this case the length is
|
||||
* encoded into the flags.
|
||||
*/
|
||||
char ary[RSTRING_EMBED_LEN_MAX + 1];
|
||||
} embed;
|
||||
} as;
|
||||
};
|
||||
|
||||
|
@ -440,7 +441,7 @@ rbimpl_rstring_getmem(VALUE str)
|
|||
/* Expecting compilers to optimize this on-stack struct away. */
|
||||
struct RString retval;
|
||||
retval.as.heap.len = RSTRING_EMBED_LEN(str);
|
||||
retval.as.heap.ptr = RSTRING(str)->as.ary;
|
||||
retval.as.heap.ptr = RSTRING(str)->as.embed.ary;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue