You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/02/13 22:45:54 UTC
[04/16] lucy-clownfish git commit: Consolidate String refcounting
routines.
Consolidate String refcounting routines.
Instead of having String override Inc_RefCount, special-case its
behavior within the main incref routine.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/cd6c304b
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cd6c304b
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cd6c304b
Branch: refs/heads/master
Commit: cd6c304bc96ed8d0bf3395327e6c281eafd564b7
Parents: 93c2bfd
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 09:04:25 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 09:04:25 2015 -0800
----------------------------------------------------------------------
runtime/c/src/Clownfish/Obj.c | 16 ++++++++++++++++
runtime/core/Clownfish/String.c | 15 +++------------
runtime/core/Clownfish/String.cfh | 4 ++--
runtime/perl/xs/XSBind.c | 15 +++++++++++++++
4 files changed, 36 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/c/src/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c
index e17feef..296192d 100644
--- a/runtime/c/src/Clownfish/Obj.c
+++ b/runtime/c/src/Clownfish/Obj.c
@@ -21,6 +21,7 @@
#include "Clownfish/Obj.h"
#include "Clownfish/Err.h"
+#include "Clownfish/String.h"
uint32_t
Obj_Get_RefCount_IMP(Obj *self) {
@@ -39,6 +40,14 @@ SI_immortal(cfish_Class *klass) {
return false;
}
+static CFISH_INLINE bool
+SI_is_string(cfish_Class *klass) {
+ if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
+ return true;
+ }
+ return false;
+}
+
Obj*
cfish_inc_refcount(void *vself) {
Obj *self = (Obj*)vself;
@@ -46,6 +55,13 @@ cfish_inc_refcount(void *vself) {
if (SI_immortal(klass)) {
return self;
}
+ else if (SI_is_string(klass)
+ && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
+ ) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
else {
self->refcount++;
return self;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index 55eec0c..3b7fe7b 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -169,18 +169,9 @@ S_new_substring(String *string, size_t byte_offset, size_t size) {
return self;
}
-Obj*
-Str_Inc_RefCount_IMP(String *self) {
- if (self->origin == NULL) {
- // Copy wrapped strings when the refcount is increased.
- String *copy = (String*)Class_Make_Obj(STRING);
- return (Obj*)Str_init_from_trusted_utf8(copy, self->ptr, self->size);
- }
- else {
- Str_Inc_RefCount_t super_incref
- = SUPER_METHOD_PTR(STRING, CFISH_Str_Inc_RefCount);
- return super_incref(self);
- }
+bool
+Str_Is_Copy_On_IncRef_IMP(String *self) {
+ return self->origin == NULL;
}
void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 32f37a7..8fe7cc5 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -203,8 +203,8 @@ class Clownfish::String nickname Str
public incremented String*
Clone(String *self);
- incremented Obj*
- Inc_RefCount(String *self);
+ bool
+ Is_Copy_On_IncRef(String *self);
public void
Destroy(String *self);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index ca58dfe..07e3fc6 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -608,6 +608,14 @@ SI_immortal(cfish_Class *klass) {
return false;
}
+static CFISH_INLINE bool
+SI_is_string(cfish_Class *klass) {
+ if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
+ return true;
+ }
+ return false;
+}
+
static void
S_lazy_init_host_obj(cfish_Obj *self) {
SV *inner_obj = newSV(0);
@@ -648,6 +656,13 @@ cfish_inc_refcount(void *vself) {
if (SI_immortal(klass)) {
return self;
}
+ else if (SI_is_string(klass)
+ && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
+ ) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
if (self->ref.count & XSBIND_REFCOUNT_FLAG) {
if (self->ref.count == XSBIND_REFCOUNT_FLAG) {