diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-20 09:39:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-20 09:39:22 +0000 |
commit | 06e935a1267a43031a47472c93ed944e2bcf5dfc (patch) | |
tree | e7a6fb4e7c8d9edaa8214c87a66a4ec251712319 /include | |
parent | 6de2f601af43364b284dea4c133329da2ac80da9 (diff) | |
download | ruby-06e935a1267a43031a47472c93ed944e2bcf5dfc.tar.gz |
* include/ruby/ruby.h (RSTRING_GETMEM): new macro to get ptr and
len at once.
* string.c (rb_str_cmp, str_eql, rb_str_eql): trivial improvements.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/ruby.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 7fcbf33bda..936493c028 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -647,10 +647,12 @@ struct RString { #define RSTRING_NOEMBED FL_USER1 #define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6) #define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2) +#define RSTRING_EMBED_LEN(str) \ + (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ + (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) #define RSTRING_LEN(str) \ (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ - (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ - (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) : \ + RSTRING_EMBED_LEN(str) : \ RSTRING(str)->as.heap.len) #define RSTRING_PTR(str) \ (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ @@ -658,11 +660,13 @@ struct RString { RSTRING(str)->as.heap.ptr) #define RSTRING_END(str) \ (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ - (RSTRING(str)->as.ary + \ - ((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ - (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT))) : \ + (RSTRING(str)->as.ary + RSTRING_EMBED_LEN(str)) : \ (RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len)) #define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str)) +#define RSTRING_GETMEM(str, ptrvar, lenvar) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + ((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \ + ((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len)) #define RARRAY_EMBED_LEN_MAX 3 struct RArray { |