parsav  Diff

Differences From Artifact [d10508934e]:

To Artifact [8aa8839430]:


    15     15   	local p = m.ptr(ty:astype())
    16     16   	return `p {
    17     17   		ptr = [&ty:astype()](m.heapa_raw(sizeof(ty) * sz));
    18     18   		ct = sz;
    19     19   	}
    20     20   end)
    21     21   
    22         -function m.cache(ty,sz)
           22  +function m.cache(ty,sz,autofree)
    23     23   	sz = sz or 32
    24     24   	local struct c {
    25     25   		store: ty[sz]
    26     26   		top: intptr
    27     27   		cur: intptr
    28     28   	}
    29     29   	c.name = string.format('cache<%s,%u>', tostring(ty), sz)
................................................................................
    33     33   		end
    34     34   		self.store[self.cur] = v
    35     35   		self.top = lib.math.biggest(self.top, self.cur + 1)
    36     36   		self.cur = (self.cur + 1) % sz
    37     37   		return v
    38     38   	end
    39     39   	c.metamethods.__apply = terra(self: &c, idx: intptr) return &self.store[idx] end
    40         -	if ty.ptr_basetype then
           40  +	if autofree then
    41     41   		terra c:free()
    42     42   			for i=0,self.top do self.store[i]:free() end
    43     43   		end
    44     44   	end
    45     45   	return c
    46     46   end
    47     47