This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/BKE_outliner_treehash.hh
Julian Eisel 8115d31248 Outliner: (Refactor) Use C++ map instead of GHash
This container is type safe and contains a few nice optimizations,
although they shouldn't make a big difference here in practice. The
hashing now uses our default hashing method which reduces code
complexity and seems to perform slightly better in my tests.

For a Heist shot with a highly complex library overrides hierarchy in
the Outliner this reduces the tree building time from around 25 to 23.6
seconds here. However the main design change for performance is yet to
come, all this is just general code refactoring (which at least
shouldn't make performance worse).
2022-08-19 22:21:04 +02:00

77 lines
2.1 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup bke
*
* Hash table of tree-store elements (#TreeStoreElem) for fast lookups via a (id, type, index)
* tuple as key.
*
* The Outliner may have to perform many lookups for rebuilding complex trees, so this should be
* treated as performance sensitive.
*/
#include <memory>
#include "BLI_map.hh"
struct BLI_mempool;
struct ID;
struct TreeStoreElem;
namespace blender::bke::outliner::treehash {
/* -------------------------------------------------------------------- */
class TreeStoreElemKey {
public:
ID *id = nullptr;
short type = 0;
short nr = 0;
explicit TreeStoreElemKey(const TreeStoreElem &elem);
TreeStoreElemKey(ID *id, short type, short nr);
uint64_t hash() const;
friend bool operator==(const TreeStoreElemKey &a, const TreeStoreElemKey &b);
};
/* -------------------------------------------------------------------- */
class TreeHash {
Map<TreeStoreElemKey, std::unique_ptr<class TseGroup>> elem_groups_;
public:
~TreeHash();
/** Create and fill hash-table with treestore elements */
static std::unique_ptr<TreeHash> create_from_treestore(BLI_mempool &treestore);
/** Full rebuild for already allocated hash-table. */
void rebuild_from_treestore(BLI_mempool &treestore);
/** Clear element usage flags. */
void clear_used();
/** Add hash-table element. */
void add_element(TreeStoreElem &elem);
/** Remove hash-table element. */
void remove_element(TreeStoreElem &elem);
/** Find first unused element with specific type, nr and id. */
TreeStoreElem *lookup_unused(short type, short nr, ID *id) const;
/** Find user or unused element with specific type, nr and id. */
TreeStoreElem *lookup_any(short type, short nr, ID *id) const;
private:
TreeHash() = default;
TseGroup *lookup_group(const TreeStoreElemKey &key) const;
TseGroup *lookup_group(const TreeStoreElem &elem) const;
TseGroup *lookup_group(short type, short nr, ID *id) const;
void fill_treehash(BLI_mempool &treestore);
};
} // namespace blender::bke::outliner::treehash