Skip to content

Instantly share code, notes, and snippets.

@samcv
Created July 19, 2017 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/b49dd434d5eba07663eb7a7b386f30b5 to your computer and use it in GitHub Desktop.
Save samcv/b49dd434d5eba07663eb7a7b386f30b5 to your computer and use it in GitHub Desktop.
diff --git a/src/strings/ops.c b/src/strings/ops.c
index 3097e63e..3712d087 100644
--- a/src/strings/ops.c
+++ b/src/strings/ops.c
@@ -76,24 +76,28 @@ static MVMString * collapse_strands(MVMThreadContext *tc, MVMString *orig) {
});
ographs = MVM_string_graphs(tc, orig);
result->body.num_graphs = ographs;
- result->body.storage_type = MVM_STRING_GRAPHEME_32;
- result->body.storage.blob_32 = MVM_malloc(ographs * sizeof(MVMGrapheme32));
+ result->body.storage_type = MVM_STRING_GRAPHEME_8;
+ result->body.storage.blob_8 = MVM_malloc(ographs * sizeof(MVMGrapheme8));
MVM_string_gi_init(tc, &gi, orig);
for (i = 0; i < ographs; i++) {
MVMGrapheme32 g = MVM_string_gi_get_grapheme(tc, &gi);
- result->body.storage.blob_32[i] = g;
+ result->body.storage.blob_8[i] = g;
if (!can_fit_into_8bit(g)) {
+ /* If we get here, we saw a codepoint lower than -127 or higher than 127
+ * so turn it into a 32 bit string instead */
+ MVM_free(result->body.storage.blob_8);
+ result->body.num_graphs = ographs;
+ result->body.storage_type = MVM_STRING_GRAPHEME_32;
+ result->body.storage.blob_32 = MVM_malloc(ographs * sizeof(MVMGrapheme32));
+ MVM_string_gi_init(tc, &gi, orig);
/* If we know we can't fit into 8 bits, enter a tighter loop for maximum speed */
- for (i++; i < ographs; i++) {
+ for (i = 0; i < ographs; i++) {
result->body.storage.blob_32[i] = MVM_string_gi_get_grapheme(tc, &gi);
}
return result;
}
}
- /* If we get here, we didn't see any cp's lower than -127 or higher than 127
- * so turn it into an 8 bit string */
- turn_32bit_into_8bit_unchecked(tc, result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment