1 #ifndef _NDB_IMSTRING_H_
2 #define _NDB_IMSTRING_H_
17 * Not-really-immutable string, for perf reasons. Also can use
24 friend class base_imstring;
26 // we can't really support keys > 65536, but most DBs impose
28 typedef uint16_t internal_size_type;
30 static inline ALWAYS_INLINE internal_size_type
33 INVARIANT(l <= std::numeric_limits<internal_size_type>::max());
37 static event_counter g_evt_imstring_bytes_allocated;
38 static event_counter g_evt_imstring_bytes_freed;
39 static event_avg_counter g_evt_avg_imstring_len;
42 base_imstring() : p(NULL), l(0) {}
44 base_imstring(const uint8_t *src, size_t l)
45 : p(new uint8_t[l]), l(CheckBounds(l))
47 g_evt_imstring_bytes_allocated += l;
48 g_evt_avg_imstring_len.offer(l);
49 NDB_MEMCPY(p, src, l);
52 base_imstring(const std::string &s)
53 : p(new uint8_t[s.size()]), l(CheckBounds(s.size()))
55 g_evt_imstring_bytes_allocated += l;
56 g_evt_avg_imstring_len.offer(l);
57 NDB_MEMCPY(p, s.data(), l);
60 base_imstring(const base_imstring &) = delete;
61 base_imstring(base_imstring &&) = delete;
62 base_imstring &operator=(const base_imstring &) = delete;
66 swap(base_imstring<R> &that)
68 // std::swap() doesn't work for packed elems
69 uint8_t * const temp_p = p;
72 internal_size_type const temp_l = l;
81 g_evt_imstring_bytes_freed += l;
84 inline const uint8_t *
103 rcu::s_instance.free_array(p);
110 internal_size_type l;
114 event_counter base_imstring<RCU>::g_evt_imstring_bytes_allocated("imstring_bytes_allocated");
117 event_counter base_imstring<RCU>::g_evt_imstring_bytes_freed("imstring_bytes_freed");
120 event_avg_counter base_imstring<RCU>::g_evt_avg_imstring_len("avg_imstring_len");
122 typedef base_imstring<false> imstring;
123 typedef base_imstring<true> rcu_imstring;
125 #endif /* _NDB_IMSTRING_H_ */