shithub: mc

ref: 8eef2702d6533ca399758c38acedf0f086b93e13
dir: /lib/std/slpush.myr/

View raw version
use "types.use"
use "alloc.use"

pkg std =
	generic slpush	: (sl : @a[:], elt : @a	-> @a[:])
;;

generic slpush = {sl, elt
	/*
	slpush relies on implementation details
	of slgrow for efficiency. Because bucket
	sizes come in powers of two for all buckets
	<= 32k, and we only reallocate when we hit
	a bucket boundary, this is effectively
	growing the slice by powers of two.
	*/
	sl = slgrow(sl, sl.len + 1)
	sl[sl.len - 1] = elt
	-> sl
}