You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/09/28 19:33:09 UTC
[lucy-commits] [09/11] git commit: refs/heads/cfish-string-prep1 - Deduplicate some
CharBuf code
Deduplicate some CharBuf code
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2fd58a14
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2fd58a14
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2fd58a14
Branch: refs/heads/cfish-string-prep1
Commit: 2fd58a1429566f8b61d2bdedbba6e5dc5b667b89
Parents: 6e6c115
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 28 19:04:56 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 28 19:04:56 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/CharBuf.c | 60 +++++++++++++------------
1 file changed, 31 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/2fd58a14/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index 6eb9c2e..8dbeb36 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -322,36 +322,52 @@ CB_Clone_IMP(CharBuf *self) {
return CB_new_from_trusted_utf8(self->ptr, self->size);
}
+static CFISH_INLINE void
+SI_mimic_utf8(CharBuf *self, const char* ptr, size_t size) {
+ if (size >= self->cap) { CB_Grow(self, size); }
+ memmove(self->ptr, ptr, size);
+ self->size = size;
+ self->ptr[size] = '\0';
+}
+
void
CB_Mimic_Utf8_IMP(CharBuf *self, const char* ptr, size_t size) {
if (!StrHelp_utf8_valid(ptr, size)) {
DIE_INVALID_UTF8(ptr, size);
}
- if (size >= self->cap) { CB_Grow(self, size); }
- memmove(self->ptr, ptr, size);
- self->size = size;
- self->ptr[size] = '\0';
+ SI_mimic_utf8(self, ptr, size);
}
void
CB_Mimic_IMP(CharBuf *self, Obj *other) {
+ const char *ptr;
+ size_t size;
if (Obj_Is_A(other, CHARBUF)) {
CharBuf *twin = (CharBuf*)other;
- if (twin->size >= self->cap) { CB_Grow(self, twin->size); }
- memmove(self->ptr, twin->ptr, twin->size);
- self->size = twin->size;
- self->ptr[twin->size] = '\0';
+ ptr = twin->ptr;
+ size = twin->size;
}
else if (Obj_Is_A(other, STRING)) {
String *twin = (String*)other;
- if (twin->size >= self->cap) { CB_Grow(self, twin->size); }
- memmove(self->ptr, twin->ptr, twin->size);
- self->size = twin->size;
- self->ptr[twin->size] = '\0';
+ ptr = twin->ptr;
+ size = twin->size;
}
else {
THROW(ERR, "CharBuf can't mimic %o", Obj_Get_Class_Name(other));
}
+ SI_mimic_utf8(self, ptr, size);
+}
+
+static CFISH_INLINE void
+SI_cat_utf8(CharBuf *self, const char* ptr, size_t size) {
+ const size_t new_size = self->size + size;
+ if (new_size >= self->cap) {
+ size_t amount = Memory_oversize(new_size, sizeof(char));
+ CB_Grow(self, amount);
+ }
+ memcpy(self->ptr + self->size, ptr, size);
+ self->size = new_size;
+ self->ptr[new_size] = '\0';
}
void
@@ -359,31 +375,17 @@ CB_Cat_Utf8_IMP(CharBuf *self, const char* ptr, size_t size) {
if (!StrHelp_utf8_valid(ptr, size)) {
DIE_INVALID_UTF8(ptr, size);
}
- CB_Cat_Trusted_Utf8_IMP(self, ptr, size);
+ SI_cat_utf8(self, ptr, size);
}
void
CB_Cat_Trusted_Utf8_IMP(CharBuf *self, const char* ptr, size_t size) {
- const size_t new_size = self->size + size;
- if (new_size >= self->cap) {
- size_t amount = Memory_oversize(new_size, sizeof(char));
- CB_Grow(self, amount);
- }
- memcpy((self->ptr + self->size), ptr, size);
- self->size = new_size;
- self->ptr[new_size] = '\0';
+ SI_cat_utf8(self, ptr, size);
}
void
CB_Cat_IMP(CharBuf *self, String *string) {
- const size_t new_size = self->size + string->size;
- if (new_size >= self->cap) {
- size_t amount = Memory_oversize(new_size, sizeof(char));
- CB_Grow(self, amount);
- }
- memcpy((self->ptr + self->size), string->ptr, string->size);
- self->size = new_size;
- self->ptr[new_size] = '\0';
+ SI_cat_utf8(self, string->ptr, string->size);
}
void