21 ndbcachefree(Ndbcache *c)
31 ndbcopy(Ndb *db, Ndbtuple *from_t, Ndbs *from_s, Ndbs *to_s)
33 Ndbtuple *first, *to_t, *last, *line;
44 for(; from_t != nil; from_t = from_t->entry){
45 to_t = ndbnew(from_t->attr, from_t->val);
47 /* have s point to matching tuple */
48 if(from_s->t == from_t)
65 newline = from_t->line != from_t->entry;
67 ndbsetmalloctag(first, getcallerpc(&db));
72 * if found, move to front
75 _ndbcachesearch(Ndb *db, Ndbs *s, char *attr, char *val, Ndbtuple **t)
81 for(l = &db->cache; *l != nil; l = &(*l)->next){
83 if(strcmp(c->attr, attr) == 0 && strcmp(c->val, val) == 0)
94 *t = ndbcopy(db, c->t, &c->s, s);
99 _ndbcacheadd(Ndb *db, Ndbs *s, char *attr, char *val, Ndbtuple *t)
103 c = mallocz(sizeof *c, 1);
106 c->attr = strdup(attr);
109 c->val = strdup(val);
112 c->t = ndbcopy(db, t, s, &c->s);
113 if(c->t == nil && t != nil)
121 if(db->ncache < Maxcached){
125 for(l = &db->cache; (*l)->next; l = &(*l)->next)
131 ndbsetmalloctag(t, getcallerpc(&db));
136 _ndbcacheflush(Ndb *db)
140 while(db->cache != nil){