Blender V5.3
ustring.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_ustring.hh"
10
11#include "BLI_concurrent_set.hh"
12
13namespace blender {
14
17{
18 static StringTable table = []() {
19 StringTable table;
20 /* Slightly larger than the number used for a default startup. */
21 table.reserve(16384);
22 return table;
23 }();
24 return table;
25}
26
27namespace detail {
28
30{
31 /* Use the same EMPTY_ENTRY used by the default constructor so that all empty #UString instances
32 * compare equal, and so that we skip the table lookup and associated overhead for the default
33 * constructor. */
34 if (str.is_empty()) {
36 }
37
39
40 /* Avoid constructing a #std::string when the string is already stored. The TBB set
41 * implementation does not support creating the actual key type lazily. Though it isn't ideal,
42 * the second set lookup and std::string allocation only happen once per string. */
43 if (const UStringEntry *entry = table.lookup_ptr(str)) {
44 return *entry;
45 }
46 return table.lookup_key_or_add({std::string(str), hash_string(str)});
47}
48
53
54} // namespace detail
55
56} // namespace blender
void reserve(const int64_t n)
const Key & lookup_key_or_add(const Key &key)
const Key * lookup_ptr(const ForwardKey &key) const
constexpr StringRef()
static constexpr blender::detail::UStringEntry EMPTY_ENTRY
#define str(s)
const blender::detail::UStringEntry & ustring_ensure_entry(StringRef str)
Definition ustring.cc:29
BMesh Iterators.
static StringTable & global_string_table()
Definition ustring.cc:16
constexpr uint64_t hash_string(StringRef str)
Definition BLI_hash.hh:183
ConcurrentSet< blender::detail::UStringEntry > StringTable
Definition ustring.cc:15