Adjust for immutable Float/Integer
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/40223249 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/40223249 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/40223249 Branch: refs/heads/master Commit: 40223249cbd7dd2cbf7cc0d983ca784dc1e5bae3 Parents: 1d2632f Author: Nick Wellnhofer <[email protected]> Authored: Thu Jul 9 17:44:28 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Sat Jul 11 14:53:49 2015 +0200 ---------------------------------------------------------------------- c/src/Lucy/Index/Inverter.c | 19 +++++++++---------- core/Lucy/Index/Inverter.c | 22 +--------------------- perl/xs/Lucy/Index/Inverter.c | 23 ++++++++++------------- 3 files changed, 20 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/40223249/c/src/Lucy/Index/Inverter.c ---------------------------------------------------------------------- diff --git a/c/src/Lucy/Index/Inverter.c b/c/src/Lucy/Index/Inverter.c index 9f18761..dfebb94 100644 --- a/c/src/Lucy/Index/Inverter.c +++ b/c/src/Lucy/Index/Inverter.c @@ -80,33 +80,32 @@ Inverter_Invert_Doc_IMP(Inverter *self, Doc *doc) { // Get the field value. switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) { case FType_TEXT: { - String *string = (String*)CERTIFY(obj, STRING); - DECREF(inventry_ivars->value); - inventry_ivars->value = INCREF(string); + CERTIFY(obj, STRING); break; } case FType_BLOB: { - Blob *blob = (Blob*)CERTIFY(obj, BLOB); - DECREF(inventry_ivars->value); - inventry_ivars->value = INCREF(blob); + CERTIFY(obj, BLOB); break; } case FType_INT32: case FType_INT64: { - Integer* value = (Integer*)inventry_ivars->value; - Int_Mimic(value, obj); + CERTIFY(obj, INTEGER); break; } case FType_FLOAT32: case FType_FLOAT64: { - Float* value = (Float*)inventry_ivars->value; - Float_Mimic(value, obj); + CERTIFY(obj, FLOAT); break; } default: THROW(ERR, "Unrecognized type: %o", type); } + if (inventry_ivars->value != obj) { + DECREF(inventry_ivars->value); + inventry_ivars->value = INCREF(obj); + } + Inverter_Add_Field(self, inventry); } DECREF(iter); http://git-wip-us.apache.org/repos/asf/lucy/blob/40223249/core/Lucy/Index/Inverter.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/Inverter.c b/core/Lucy/Index/Inverter.c index 92f43ac..c6d1873 100644 --- a/core/Lucy/Index/Inverter.c +++ b/core/Lucy/Index/Inverter.c @@ -211,27 +211,7 @@ InvEntry_init(InverterEntry *self, Schema *schema, String *field, ivars->sim = (Similarity*)INCREF(Schema_Fetch_Sim(schema, field)); ivars->type = (FieldType*)INCREF(Schema_Fetch_Type(schema, field)); if (!ivars->type) { THROW(ERR, "Unknown field: '%o'", field); } - - uint8_t prim_id = FType_Primitive_ID(ivars->type); - switch (prim_id & FType_PRIMITIVE_ID_MASK) { - case FType_TEXT: - ivars->value = NULL; - break; - case FType_BLOB: - ivars->value = NULL; - break; - case FType_INT32: - case FType_INT64: - ivars->value = (Obj*)Int_new(0); - break; - case FType_FLOAT32: - case FType_FLOAT64: - ivars->value = (Obj*)Float_new(0); - break; - default: - THROW(ERR, "Unrecognized primitive id: %i8", prim_id); - } - + ivars->value = NULL; ivars->indexed = FType_Indexed(ivars->type); if (ivars->indexed && FType_is_a(ivars->type, NUMERICTYPE)) { THROW(ERR, "Field '%o' spec'd as indexed, but numerical types cannot " http://git-wip-us.apache.org/repos/asf/lucy/blob/40223249/perl/xs/Lucy/Index/Inverter.c ---------------------------------------------------------------------- diff --git a/perl/xs/Lucy/Index/Inverter.c b/perl/xs/Lucy/Index/Inverter.c index f2193bd..dfd436d 100644 --- a/perl/xs/Lucy/Index/Inverter.c +++ b/perl/xs/Lucy/Index/Inverter.c @@ -92,51 +92,48 @@ LUCY_Inverter_Invert_Doc_IMP(lucy_Inverter *self, lucy_Doc *doc) { lucy_InverterEntryIVARS *const entry_ivars = lucy_InvEntry_IVARS(inv_entry); lucy_FieldType *type = entry_ivars->type; + cfish_Obj *obj = NULL; // Get the field value, forcing text fields to UTF-8. switch (LUCY_FType_Primitive_ID(type) & lucy_FType_PRIMITIVE_ID_MASK) { case lucy_FType_TEXT: { STRLEN val_len; char *val_ptr = SvPVutf8(value_sv, val_len); - CFISH_DECREF(entry_ivars->value); - entry_ivars->value - = (cfish_Obj*)cfish_Str_new_wrap_trusted_utf8( - val_ptr, val_len); + obj = (cfish_Obj*)cfish_Str_new_wrap_trusted_utf8(val_ptr, + val_len); break; } case lucy_FType_BLOB: { STRLEN val_len; char *val_ptr = SvPV(value_sv, val_len); - CFISH_DECREF(entry_ivars->value); - entry_ivars->value - = (cfish_Obj*)cfish_Blob_new_wrap(val_ptr, val_len); + obj = (cfish_Obj*)cfish_Blob_new_wrap(val_ptr, val_len); break; } case lucy_FType_INT32: { - cfish_Integer* value = (cfish_Integer*)entry_ivars->value; - CFISH_Int_Set_Value(value, SvIV(value_sv)); + obj = (cfish_Obj*)cfish_Int_new(SvIV(value_sv)); break; } case lucy_FType_INT64: { - cfish_Integer* value = (cfish_Integer*)entry_ivars->value; // nwellnhof: Using SvNOK could avoid a int/float/int // round-trip with 32-bit IVs. int64_t val = sizeof(IV) == 8 ? SvIV(value_sv) : (int64_t)SvNV(value_sv); // lossy - CFISH_Int_Set_Value(value, val); + obj = (cfish_Obj*)cfish_Int_new(val); break; } case lucy_FType_FLOAT32: case lucy_FType_FLOAT64: { - cfish_Float* value = (cfish_Float*)entry_ivars->value; - CFISH_Float_Set_Value(value, SvNV(value_sv)); + obj = (cfish_Obj*)cfish_Float_new(SvNV(value_sv)); break; } default: THROW(CFISH_ERR, "Unrecognized type: %o", type); } + CFISH_DECREF(entry_ivars->value); + entry_ivars->value = obj; + LUCY_Inverter_Add_Field(self, inv_entry); } }
