aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authorduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-16 08:24:58 +0000
committerduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-16 08:24:58 +0000
commit7fc586f7d769dbe797673b8d688a5a7b36870c31 (patch)
tree25e4f32d2f10ea1235bed8d9300faced113f0519 /string.c
parent2a08f176575cd7d132171ef3d87e0b44dc8dc2ff (diff)
downloadruby-7fc586f7d769dbe797673b8d688a5a7b36870c31.tar.gz
* enc/unicode.c: Artificial mapping to test buffer expansion code.
* string.c: Fixed buffer expansion logic. * test/ruby/enc/test_case_mapping.rb: Tests for above. (with Kimihito Matsui) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/string.c b/string.c
index c78d30fe63..20c9e34e35 100644
--- a/string.c
+++ b/string.c
@@ -5673,6 +5673,7 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc)
while (source_current < source_end) {
/* increase multiplier using buffer count to converge quickly */
int capa = (int)(source_end-source_current)*++buffer_count + CASE_MAPPING_ADDITIONAL_LENGTH;
+/* fprintf(stderr, "Buffer allocation, capa is %d\n", capa); *//* for tuning */
current_buffer->next = (mapping_buffer*)ALLOC_N(char, sizeof(mapping_buffer)+capa);
current_buffer = current_buffer->next;
current_buffer->next = NULL;
@@ -5684,13 +5685,22 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc)
current_buffer->space+current_buffer->capa,
enc);
}
+/* fprintf(stderr, "Buffer count is %d\n", buffer_count); *//* for tuning */
if (buffer_count==1)
target = rb_str_new_with_class(source, (const char*)current_buffer->space, target_length);
else {
char *target_current = RSTRING_PTR(target = rb_str_new_with_class(source, 0, target_length));
- for (current_buffer=pre_buffer.next; current_buffer; current_buffer=current_buffer->next)
+ mapping_buffer *previous_buffer;
+
+ current_buffer=pre_buffer.next;
+ while (current_buffer) {
memcpy(target_current, current_buffer->space, current_buffer->used);
+ target_current += current_buffer->used;
+ previous_buffer = current_buffer;
+ current_buffer=current_buffer->next;
+ xfree(previous_buffer);
+ }
}
/* TODO: check about string terminator character */