static struct oattr *
oa_new(struct odes *o, uns x, byte *v)
{
- struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v));
+ struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v)+1);
a->next = a->same = NULL;
a->attr = x;
+ a->val = (byte*) (a+1);
strcpy(a->val, v);
return a;
}
+static struct oattr *
+oa_new_ref(struct odes *o, uns x, byte *v)
+{
+ struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr));
+
+ a->next = a->same = NULL;
+ a->attr = x;
+ a->val = v;
+ return a;
+}
+
struct odes *
obj_new(struct mempool *pool)
{
return obj_set_attr(o, a, x);
}
-struct oattr *
-obj_add_attr(struct odes *o, uns x, byte *v)
+static inline struct oattr *
+obj_add_attr_internal(struct odes *o, uns x, byte *v, uns just_ref)
{
struct oattr *a, *b;
- b = oa_new(o, x, v);
+ if (just_ref)
+ b = oa_new_ref(o, x, v);
+ else
+ b = oa_new(o, x, v);
if (!(a = o->cached_attr) || a->attr != x)
{
if (!(a = obj_find_attr(o, x)))
return b;
}
+struct oattr *
+obj_add_attr(struct odes *o, uns x, byte *v)
+{
+ return obj_add_attr_internal(o, x, v, 0);
+}
+
+struct oattr *
+obj_add_attr_ref(struct odes *o, uns x, byte *v)
+{
+ return obj_add_attr_internal(o, x, v, 1);
+}
+
struct oattr *
obj_prepend_attr(struct odes *o, uns x, byte *v)
{
struct oattr { /* Object attribute */
struct oattr *next, *same;
byte attr;
- byte val[1];
+ byte *val;
};
void obj_dump(struct odes *);
struct oattr *obj_set_attr(struct odes *, uns, byte *);
struct oattr *obj_set_attr_num(struct odes *, uns, uns);
struct oattr *obj_add_attr(struct odes *, uns, byte *);
+struct oattr *obj_add_attr_ref(struct odes *o, uns x, byte *v); // no strdup()
struct oattr *obj_prepend_attr(struct odes *, uns, byte *);
struct oattr *obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v);
void obj_move_attr_to_head(struct odes *o, uns);