4 // Reference counted objects
7 rc_base<T>::rc_base() :
13 rc_base<T>::~rc_base()
17 // Utility type: pointer-vector.
20 ptr_vec<T>::ptr_vec(rust_dom *dom) :
24 data(new (dom) T*[alloc])
27 dom->log(rust_log::MEM,
28 "new ptr_vec(data=0x%" PRIxPTR ") -> 0x%" PRIxPTR,
29 (uintptr_t)data, (uintptr_t)this);
33 ptr_vec<T>::~ptr_vec()
36 dom->log(rust_log::MEM,
37 "~ptr_vec 0x%" PRIxPTR ", data=0x%" PRIxPTR,
38 (uintptr_t)this, (uintptr_t)data);
43 template <typename T> T *&
44 ptr_vec<T>::operator[](size_t offset) {
45 I(dom, data[offset]->idx == offset);
51 ptr_vec<T>::push(T *p)
54 I(dom, fill <= alloc);
57 data = (T **)dom->realloc(data, alloc * sizeof(T*));
74 ptr_vec<T>::trim(size_t sz)
77 if (sz <= (alloc / 4) &&
78 (alloc / 2) >= INIT_SIZE) {
80 I(dom, alloc >= fill);
81 data = (T **)dom->realloc(data, alloc * sizeof(T*));
88 ptr_vec<T>::swapdel(T *item)
90 /* Swap the endpoint into i and decr fill. */
93 I(dom, item->idx < fill);
96 T *subst = data[fill];
97 size_t idx = item->idx;
103 // Inline fn used regularly elsewhere.
106 next_power_of_two(size_t s)
114 #if SIZE_MAX == UINT64_MAX
120 // Vectors (rust-user-code level).
123 rust_vec : public rc_base<rust_vec>
128 rust_vec(rust_dom *dom, size_t alloc, size_t fill, uint8_t const *d) :
135 memcpy(&data[0], d, fill);
141 // Rust types vec and str look identical from our perspective.
142 typedef rust_vec rust_str;
148 // indent-tabs-mode: nil
150 // buffer-file-coding-system: utf-8-unix
151 // compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";