summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
AgeCommit message (Collapse)Author
2019-10-12Merge pull request #4770 from ↵Yukihiro "Matz" Matsumoto
shuujii/sHARED-string-is-not-required-when-sharing-POOL-string SHARED string is not required when sharing POOL string
2019-10-12SHARED string is not required when sharing POOL stringKOBAYASHI Shuji
The heap string buffer of POOL string always exists, does not need to be released, and read only, so it can be shared as NOFREE string.
2019-10-12Rename `str_make_shared()` to `str_share()` in `src/string.c`KOBAYASHI Shuji
Because it may not create `struct mrb_shared_string`.
2019-10-10Integrate `mrb_str_inspect` and `mrb_str_dump`KOBAYASHI Shuji
2019-10-06Remove unnecessary function: `mrb_str_freeze`.Yukihiro "Matz" Matsumoto
2019-10-04Freeze strings from `nil.to_s`, `true.to_s`, `false.to_s`.Yukihiro "Matz" Matsumoto
This is an experimental changes in Ruby 2.7.
2019-09-27Simplify arguments check in `String#rindex`KOBAYASHI Shuji
Also fix document about type of the first argument.
2019-09-26Use type predicate macros instead of `mrb_type` if possibleKOBAYASHI Shuji
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for all `enum mrb_vtype`).
2019-09-25Rename symbol-to-string functions; close #4684Yukihiro "Matz" Matsumoto
* mrb_sym2name -> mrb_sym_name * mrb_sym2name_len -> mrb_sym_name_len * mrb_sym2str -> mrb_sym_str
2019-09-19Simplify arguments check in `String#index`KOBAYASHI Shuji
Also fix document about type of the first argument.
2019-09-14Add a macro `mrb_frozen_p` that points to `MRB_FROZEN_P`.Yukihiro "Matz" Matsumoto
2019-09-14Raise an error from `String#<=>` with a non string operand.Yukihiro "Matz" Matsumoto
2019-09-12Remove `$/` from mruby implementation.Yukihiro "Matz" Matsumoto
1. `$/` and other Perl-ish global variables are not defined in ISO. 2. The current Ruby policy do not encourage those variables. 3. Those variables has global effect and can cause troubles.
2019-09-11Move `String#{getbyte,setbyte,byteslice}` to the core; #4696Yukihiro "Matz" Matsumoto
Unlike CRuby, there's no way to process strings byte-wise by core methods because there's no per string encoding in mruby, so that we moved 3 byte-wise operation methods from `mruby-string-ext` gem.
2019-08-24Suppress warning by gcc with `-Wmaybe-uninitialized`dearblue
2019-08-21Prioritize embedded string over nofree (or normal) stringKOBAYASHI Shuji
Prioritize embedded string in the following functions: - `str_new_static` - `str_new` - `mrb_str_new_capa` - `mrb_str_pool` The reasons are as follows: - Consistency with `mrb_str_byte_subseq` and `str_replace`. - Memory locality increases and may be slightly faster. - No conversion cost to embedded string when modifying the string.
2019-08-20Use `RBasic` padding for embedded string on 64-bit CPUKOBAYASHI Shuji
On 64-bit CPU, there is padding in `RBasic`, so reorder the fields and use it as buffer of embedded string. This change allows 4 more bytes to be embedded on 64-bit CPU. However, an incompatibility will occur if `RString::as::ary` is accessed directly because `RString` structure has changed.
2019-08-19Move `mrb_str_pool` to `src/string.c` to use `str_init` familyKOBAYASHI Shuji
2019-08-19Merge pull request #4638 from dearblue/simplify-get-argsYukihiro "Matz" Matsumoto
Simplify get arguments
2019-08-19Merge pull request #4641 from ↵Yukihiro "Matz" Matsumoto
shuujii/rename-mrb_shared_string-len-to-mrb_shared_string-capa Rename `mrb_shared_string::len` to `mrb_shared_string::capa`
2019-08-18Rename `mrb_shared_string::len` to `mrb_shared_string::capa`KOBAYASHI Shuji
Because this field is used as capacity of string buffer.
2019-08-18Also use `str_init_shared` for `orig` in `str_make_shared()`KOBAYASHI Shuji
2019-08-18Simplify get argumentsdearblue
- `mrb_str_index_m()` and `mrb_str_rindex()` Make `mrb_get_args()` called only once from called twice. - `mrb_str_byteslice()` Replace `goto` with `if ~ else`.
2019-08-17Merge pull request #4634 from shuujii/refactor-set-unset-string-type-flagsYukihiro "Matz" Matsumoto
Refactor set/unset string type flags
2019-08-17Refactor set/unset string type flagsKOBAYASHI Shuji
Introduce `RSTR_SET_TYPE_FLAG` macro to set the specified string type flag and clear the others.
2019-08-17Fix `String#rindex` with invalid UTF-8 stringdearblue
Previously `String#rindex` returned the wrong index when given an invalid UTF-8 string. ```terminal % ruby26 -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")' 11 % ./mruby-head -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")' nil % ./mruby-patched -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")' 11 ```
2019-08-16SHARED/FSHARED string is not required when sharing NOFREE stringKOBAYASHI Shuji
I think the string buffer of NOFREE string always exists and does not need to be released, so it can be shared as another NOFREE string. Also changed the `mrb_shared_string` field order so that eliminate padding if `int` and `mrb_int` sizes are less than pointer size.
2019-08-15Remove unneeded `#include` in `src/string.c`KOBAYASHI Shuji
2019-08-14Extract initialization code of shared and fshared string to functionKOBAYASHI Shuji
2019-08-14Small refactoring on #4630Yukihiro "Matz" Matsumoto
2019-08-13Extract `struct RString` initialization code to functionKOBAYASHI Shuji
2019-08-12Merge pull request #4626 from ↵Yukihiro "Matz" Matsumoto
shuujii/mrb_str_modify_keep_ascii-can-embed-one-more-byte `mrb_str_modify_keep_ascii` can embed one more byte
2019-08-12Replacing region may overwrap with the target region; fix #4627Yukihiro "Matz" Matsumoto
2019-08-11Add `NUL` always to short strings; ref 98fc887Yukihiro "Matz" Matsumoto
2019-08-11`mrb_str_modify_keep_ascii` can embed one more byteKOBAYASHI Shuji
The condition to make an embedded string was incorrect. Because there were several similar codes, extracted into `RSTR_EMBEDDABLE_P` macro.
2019-08-07Update `mrb_to_str` and related functions.Yukihiro "Matz" Matsumoto
Contrary to the name, `mrb_to_str` just checks type, no conversion.
2019-08-07Reorganize `mrb_string_value_cstr` and related functions.Yukihiro "Matz" Matsumoto
`mrb_string_value_cstr` and `mrb_string_value_len`: obsolete `mrb_string_cstr`: new function to retrieve NULL terminated C string `RSTRING_CSTR`: wrapper macro of `mrb_string_cstr`
2019-08-05Use new specifiers/modifiers of `mrb_vfromat()`KOBAYASHI Shuji
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in my environment than before the introduction of new specifiers/modifiers (5116789a) with this change. ------------+-------------------+-------------------+-------- BINARY | BEFORE (5116789a) | AFTER (This PR) | RATIO ------------+-------------------+-------------------+-------- mruby | 593416 bytes | 593208 bytes | -0.04% libmruby.a | 769048 bytes | 767264 bytes | -0.23% ------------+-------------------+-------------------+-------- BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613, so I put it back.
2019-07-22Set `MRB_STR_ASCII` flag in `String#inspect`KOBAYASHI Shuji
`String#inspect` can set `MRB_STR_ASCII` flag to receiver and return value because it checks character byte length.
2019-07-17Avoid `MRB_INLINE` for `mrb_str_modify()`; ref #4579Yukihiro "Matz" Matsumoto
Functions that are called infrequently need not to be inline.
2019-07-16Copy receiver's `MRB_STR_ASCII` flag in some methods of `String`KOBAYASHI Shuji
2019-07-16Merge pull request #4579 from ↵Yukihiro "Matz" Matsumoto
shuujii/keep-MRB_STR_ASCII-flag-in-some-methods-of-String Keep `MRB_STR_ASCII` flag in some methods of `String`
2019-07-15Add `MRB_API` to `mrb_str_modify_keep_ascii()`KOBAYASHI Shuji
2019-07-14Keep `MRB_STR_ASCII` flag in some methods of `String`KOBAYASHI Shuji
2019-07-14Improve `utf8len()` performance with UTF-8dearblue
2019-07-13Change type of a variable for signedness mismatch; ref #4573Yukihiro "Matz" Matsumoto
2019-07-12Fix heap buffer overflow; fix #4569dearblue
2019-07-11Improve performance `String#index` with UTF-8dearblue
Based on Boyer-Moore-Horspool algorithm (Quick Search algorithm). As a side effect, the correct position is returned even if an invalid UTF-8 string is given. ```console % ./mruby@master -e 'p ("\xd1" * 100 + "#").index("#")' 50 % ./mruby@improve-index -e 'p ("\xd1" * 100 + "#").index("#")' 100 ``` The other behavior should be the same as the current implementation.
2019-07-10Remove an unused argument of `str_with_class()`KOBAYASHI Shuji
2019-07-05Read/write `MRB_STR_ASCII` flag only when `MRB_UTF8_STRING` is definedKOBAYASHI Shuji