Permalink
Browse files

Restore check for onig version to build with 4.6

In getting replacement do not create temp string object, but directly add to resulting buffer (performance impr.)
  • Loading branch information...
1 parent fb987fe commit 6fc50146be697637f871ed4df2d0c9b29de0662e Nikolai Lugovoi committed Mar 28, 2007
Showing with 6 additions and 6 deletions.
  1. +6 −6 ext/oregexp.c
View
@@ -58,7 +58,9 @@ static OnigEncodingType * int2encoding( VALUE v_index ) {
case 26: return ONIG_ENCODING_SJIS;
/*case 27: return ONIG_ENCODING_KOI8;*/
case 28: return ONIG_ENCODING_KOI8_R;
+#if ONIGURUMA_VERSION_MAJOR == 5
case 29: return ONIG_ENCODING_CP1251;
+#endif
case 30: return ONIG_ENCODING_BIG5;
case 31: return ONIG_ENCODING_GB18030;
case 32: return ONIG_ENCODING_UNDEF;
@@ -224,14 +226,14 @@ backslash). */
/* scan the replacement text, looking for substitutions (\n) and \escapes. */
static VALUE
-oregexp_get_replacement(pat, src_text, repl_text, region)
+oregexp_append_replacement(pat, src_text, repl_text, region, ret)
VALUE pat,
src_text,
repl_text;
OnigRegion * region;
+ VALUE ret;
{
ORegexp *oregexp;
- VALUE ret;
int32_t replIdx = 0, name_pos, name_start, name_end ;
int32_t replacementLength = RSTRING(repl_text)->len;
UChar *replacementText = RSTRING(repl_text)->ptr;
@@ -248,8 +250,6 @@ oregexp_get_replacement(pat, src_text, repl_text, region)
Data_Get_Struct( pat, ORegexp, oregexp );
enc = onig_get_encoding( oregexp->reg );
- ret = rb_str_buf_new(RSTRING(repl_text)->len);
-
while (replIdx < replacementLength) {
OnigCodePoint c = ONIGENC_MBC_TO_CODE(enc, replacementText+replIdx, replacementEnd);
int c_len =ONIGENC_MBC_ENC_LEN(enc, replacementText+replIdx) ;
@@ -438,10 +438,10 @@ oregexp_gsub(self, argc, argv, bang, once, region)
block_res = rb_yield( match_data );
str_mod_check( string_str, str_ptr, str_len);
curr_repl = rb_obj_as_string(block_res);
+ rb_str_append(buf, curr_repl);
} else {
- curr_repl = oregexp_get_replacement(self, string_str, repl, region);
+ oregexp_append_replacement(self, string_str, repl, region, buf);
}
- rb_str_append(buf, curr_repl);
if( once ) break;
// find next match
if( end == beg) {

0 comments on commit 6fc5014

Please sign in to comment.