Store number fields in documents as Perl IVs and NVs

Inverter_Invert_Doc expects IVs or NVs in number fields. It would be
more efficient if Clownfish::Objs were supported as well. But this
matters only in the unusual case of creating documents from C space
like in the test suite.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/684e52b0
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/684e52b0
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/684e52b0

Branch: refs/heads/master
Commit: 684e52b002ae71ec2f94a6373d5b17f4ef4ac0f2
Parents: e3c9fa8
Author: Nick Wellnhofer <[email protected]>
Authored: Sat May 23 16:35:24 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat May 23 17:09:12 2015 +0200

----------------------------------------------------------------------
 perl/xs/Lucy/Document/Doc.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/684e52b0/perl/xs/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Document/Doc.c b/perl/xs/Lucy/Document/Doc.c
index d65062d..97ab055 100644
--- a/perl/xs/Lucy/Document/Doc.c
+++ b/perl/xs/Lucy/Document/Doc.c
@@ -60,11 +60,7 @@ LUCY_Doc_Store_IMP(lucy_Doc *self, cfish_String *field, 
cfish_Obj *value) {
     const char *key      = CFISH_Str_Get_Ptr8(field);
     size_t      key_size = CFISH_Str_Get_Size(field);
     SV *key_sv = newSVpvn(key, key_size);
-    SV *val_sv = value == NULL
-                 ? newSV(0)
-                 : CFISH_Obj_Is_A(value, CFISH_STRING)
-                 ? XSBind_str_to_sv(aTHX_ (cfish_String*)value)
-                 : (SV*)CFISH_Obj_To_Host(value);
+    SV *val_sv = XSBind_cfish_to_perl(aTHX_ value);
     SvUTF8_on(key_sv);
     (void)hv_store_ent((HV*)ivars->fields, key_sv, val_sv, 0);
     // TODO: make this a thread-local instead of creating it every time?
@@ -155,17 +151,8 @@ LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field) {
     SV **sv_ptr = hv_fetch((HV*)ivars->fields, CFISH_Str_Get_Ptr8(field),
                            CFISH_Str_Get_Size(field), 0);
 
-    if (sv_ptr && XSBind_sv_defined(aTHX_ *sv_ptr)) {
-        SV *const sv = *sv_ptr;
-        if (sv_isobject(sv) && sv_derived_from(sv, "Clownfish::Obj")) {
-            IV tmp = SvIV(SvRV(sv));
-            retval = CFISH_INCREF(INT2PTR(cfish_Obj*, tmp));
-        }
-        else {
-            STRLEN size;
-            char *ptr = SvPVutf8(sv, size);
-            retval = (cfish_Obj*)cfish_Str_new_wrap_trusted_utf8(ptr, size);
-        }
+    if (sv_ptr) {
+        retval = XSBind_perl_to_cfish(aTHX_ *sv_ptr);
     }
 
     return retval;

Reply via email to