diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-03 15:15:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-03 15:16:02 +0300 |
commit | d64803f63b4311b0abb93542a907e97b47493e9f (patch) | |
tree | c9c43b768859393d1b4b1d8c0bca84081606b19a /source | |
parent | e797c4f28f50f2be9d6d28d4b8e5c080d53ef74f (diff) |
Cleanup: Use trailing underscore for non-public data members
This makes the code conform better with our style guide.
Diffstat (limited to 'source')
26 files changed, 1239 insertions, 1242 deletions
diff --git a/source/blender/blenkernel/BKE_derived_node_tree.hh b/source/blender/blenkernel/BKE_derived_node_tree.hh index 84b36f675e0..59f38355330 100644 --- a/source/blender/blenkernel/BKE_derived_node_tree.hh +++ b/source/blender/blenkernel/BKE_derived_node_tree.hh @@ -45,9 +45,9 @@ class DerivedNodeTree; class DSocket : NonCopyable, NonMovable { protected: - DNode *m_node; - const SocketRef *m_socket_ref; - uint m_id; + DNode *node_; + const SocketRef *socket_ref_; + uint id_; friend DerivedNodeTree; @@ -76,8 +76,8 @@ class DSocket : NonCopyable, NonMovable { class DInputSocket : public DSocket { private: - Vector<DOutputSocket *> m_linked_sockets; - Vector<DGroupInput *> m_linked_group_inputs; + Vector<DOutputSocket *> linked_sockets_; + Vector<DGroupInput *> linked_group_inputs_; friend DerivedNodeTree; @@ -92,7 +92,7 @@ class DInputSocket : public DSocket { class DOutputSocket : public DSocket { private: - Vector<DInputSocket *> m_linked_sockets; + Vector<DInputSocket *> linked_sockets_; friend DerivedNodeTree; @@ -103,10 +103,10 @@ class DOutputSocket : public DSocket { class DGroupInput : NonCopyable, NonMovable { private: - const InputSocketRef *m_socket_ref; - DParentNode *m_parent; - Vector<DInputSocket *> m_linked_sockets; - uint m_id; + const InputSocketRef *socket_ref_; + DParentNode *parent_; + Vector<DInputSocket *> linked_sockets_; + uint id_; friend DerivedNodeTree; @@ -121,13 +121,13 @@ class DGroupInput : NonCopyable, NonMovable { class DNode : NonCopyable, NonMovable { private: - const NodeRef *m_node_ref; - DParentNode *m_parent; + const NodeRef *node_ref_; + DParentNode *parent_; - Span<DInputSocket *> m_inputs; - Span<DOutputSocket *> m_outputs; + Span<DInputSocket *> inputs_; + Span<DOutputSocket *> outputs_; - uint m_id; + uint id_; friend DerivedNodeTree; @@ -153,9 +153,9 @@ class DNode : NonCopyable, NonMovable { class DParentNode : NonCopyable, NonMovable { private: - const NodeRef *m_node_ref; - DParentNode *m_parent; - uint m_id; + const NodeRef *node_ref_; + DParentNode *parent_; + uint id_; friend DerivedNodeTree; @@ -169,17 +169,17 @@ using NodeTreeRefMap = Map<bNodeTree *, std::unique_ptr<const NodeTreeRef>>; class DerivedNodeTree : NonCopyable, NonMovable { private: - LinearAllocator<> m_allocator; - bNodeTree *m_btree; - Vector<DNode *> m_nodes_by_id; - Vector<DGroupInput *> m_group_inputs; - Vector<DParentNode *> m_parent_nodes; + LinearAllocator<> allocator_; + bNodeTree *btree_; + Vector<DNode *> nodes_by_id_; + Vector<DGroupInput *> group_inputs_; + Vector<DParentNode *> parent_nodes_; - Vector<DSocket *> m_sockets_by_id; - Vector<DInputSocket *> m_input_sockets; - Vector<DOutputSocket *> m_output_sockets; + Vector<DSocket *> sockets_by_id_; + Vector<DInputSocket *> input_sockets_; + Vector<DOutputSocket *> output_sockets_; - Map<const bNodeType *, Vector<DNode *>> m_nodes_by_type; + Map<const bNodeType *, Vector<DNode *>> nodes_by_type_; public: DerivedNodeTree(bNodeTree *btree, NodeTreeRefMap &node_tree_refs); @@ -235,27 +235,27 @@ class DerivedNodeTree : NonCopyable, NonMovable { inline const DNode &DSocket::node() const { - return *m_node; + return *node_; } inline uint DSocket::id() const { - return m_id; + return id_; } inline uint DSocket::index() const { - return m_socket_ref->index(); + return socket_ref_->index(); } inline bool DSocket::is_input() const { - return m_socket_ref->is_input(); + return socket_ref_->is_input(); } inline bool DSocket::is_output() const { - return m_socket_ref->is_output(); + return socket_ref_->is_output(); } inline const DSocket &DSocket::as_base() const @@ -275,32 +275,32 @@ inline const DOutputSocket &DSocket::as_output() const inline PointerRNA *DSocket::rna() const { - return m_socket_ref->rna(); + return socket_ref_->rna(); } inline StringRefNull DSocket::idname() const { - return m_socket_ref->idname(); + return socket_ref_->idname(); } inline StringRefNull DSocket::name() const { - return m_socket_ref->name(); + return socket_ref_->name(); } inline const SocketRef &DSocket::socket_ref() const { - return *m_socket_ref; + return *socket_ref_; } inline bNodeSocket *DSocket::bsocket() const { - return m_socket_ref->bsocket(); + return socket_ref_->bsocket(); } inline bool DSocket::is_available() const { - return (m_socket_ref->bsocket()->flag & SOCK_UNAVAIL) == 0; + return (socket_ref_->bsocket()->flag & SOCK_UNAVAIL) == 0; } /* -------------------------------------------------------------------- @@ -309,22 +309,22 @@ inline bool DSocket::is_available() const inline const InputSocketRef &DInputSocket::socket_ref() const { - return m_socket_ref->as_input(); + return socket_ref_->as_input(); } inline Span<const DOutputSocket *> DInputSocket::linked_sockets() const { - return m_linked_sockets.as_span(); + return linked_sockets_.as_span(); } inline Span<const DGroupInput *> DInputSocket::linked_group_inputs() const { - return m_linked_group_inputs.as_span(); + return linked_group_inputs_.as_span(); } inline bool DInputSocket::is_linked() const { - return m_linked_sockets.size() > 0 || m_linked_group_inputs.size() > 0; + return linked_sockets_.size() > 0 || linked_group_inputs_.size() > 0; } /* -------------------------------------------------------------------- @@ -333,12 +333,12 @@ inline bool DInputSocket::is_linked() const inline const OutputSocketRef &DOutputSocket::socket_ref() const { - return m_socket_ref->as_output(); + return socket_ref_->as_output(); } inline Span<const DInputSocket *> DOutputSocket::linked_sockets() const { - return m_linked_sockets.as_span(); + return linked_sockets_.as_span(); } /* -------------------------------------------------------------------- @@ -347,32 +347,32 @@ inline Span<const DInputSocket *> DOutputSocket::linked_sockets() const inline const InputSocketRef &DGroupInput::socket_ref() const { - return *m_socket_ref; + return *socket_ref_; } inline bNodeSocket *DGroupInput::bsocket() const { - return m_socket_ref->bsocket(); + return socket_ref_->bsocket(); } inline const DParentNode *DGroupInput::parent() const { - return m_parent; + return parent_; } inline Span<const DInputSocket *> DGroupInput::linked_sockets() const { - return m_linked_sockets.as_span(); + return linked_sockets_.as_span(); } inline uint DGroupInput::id() const { - return m_id; + return id_; } inline StringRefNull DGroupInput::name() const { - return m_socket_ref->name(); + return socket_ref_->name(); } /* -------------------------------------------------------------------- @@ -381,52 +381,52 @@ inline StringRefNull DGroupInput::name() const inline const NodeRef &DNode::node_ref() const { - return *m_node_ref; + return *node_ref_; } inline const DParentNode *DNode::parent() const { - return m_parent; + return parent_; } inline Span<const DInputSocket *> DNode::inputs() const { - return m_inputs; + return inputs_; } inline Span<const DOutputSocket *> DNode::outputs() const { - return m_outputs; + return outputs_; } inline const DInputSocket &DNode::input(uint index) const { - return *m_inputs[index]; + return *inputs_[index]; } inline const DOutputSocket &DNode::output(uint index) const { - return *m_outputs[index]; + return *outputs_[index]; } inline uint DNode::id() const { - return m_id; + return id_; } inline PointerRNA *DNode::rna() const { - return m_node_ref->rna(); + return node_ref_->rna(); } inline StringRefNull DNode::idname() const { - return m_node_ref->idname(); + return node_ref_->idname(); } inline StringRefNull DNode::name() const { - return m_node_ref->name(); + return node_ref_->name(); } /* -------------------------------------------------------------------- @@ -435,17 +435,17 @@ inline StringRefNull DNode::name() const inline const DParentNode *DParentNode::parent() const { - return m_parent; + return parent_; } inline const NodeRef &DParentNode::node_ref() const { - return *m_node_ref; + return *node_ref_; } inline uint DParentNode::id() const { - return m_id; + return id_; } /* -------------------------------------------------------------------- @@ -454,7 +454,7 @@ inline uint DParentNode::id() const inline Span<const DNode *> DerivedNodeTree::nodes() const { - return m_nodes_by_id.as_span(); + return nodes_by_id_.as_span(); } inline Span<const DNode *> DerivedNodeTree::nodes_by_type(StringRefNull idname) const @@ -465,7 +465,7 @@ inline Span<const DNode *> DerivedNodeTree::nodes_by_type(StringRefNull idname) inline Span<const DNode *> DerivedNodeTree::nodes_by_type(const bNodeType *nodetype) const { - const Vector<DNode *> *nodes = m_nodes_by_type.lookup_ptr(nodetype); + const Vector<DNode *> *nodes = nodes_by_type_.lookup_ptr(nodetype); if (nodes == nullptr) { return {}; } @@ -476,22 +476,22 @@ inline Span<const DNode *> DerivedNodeTree::nodes_by_type(const bNodeType *nodet inline Span<const DSocket *> DerivedNodeTree::sockets() const { - return m_sockets_by_id.as_span(); + return sockets_by_id_.as_span(); } inline Span<const DInputSocket *> DerivedNodeTree::input_sockets() const { - return m_input_sockets.as_span(); + return input_sockets_.as_span(); } inline Span<const DOutputSocket *> DerivedNodeTree::output_sockets() const { - return m_output_sockets.as_span(); + return output_sockets_.as_span(); } inline Span<const DGroupInput *> DerivedNodeTree::group_inputs() const { - return m_group_inputs.as_span(); + return group_inputs_.as_span(); } } // namespace bke diff --git a/source/blender/blenkernel/BKE_node_tree_ref.hh b/source/blender/blenkernel/BKE_node_tree_ref.hh index 557eb44e5df..619a84f6914 100644 --- a/source/blender/blenkernel/BKE_node_tree_ref.hh +++ b/source/blender/blenkernel/BKE_node_tree_ref.hh @@ -69,14 +69,14 @@ class NodeTreeRef; class SocketRef : NonCopyable, NonMovable { protected: - NodeRef *m_node; - bNodeSocket *m_bsocket; - bool m_is_input; - uint m_id; - uint m_index; - PointerRNA m_rna; - Vector<SocketRef *> m_linked_sockets; - Vector<SocketRef *> m_directly_linked_sockets; + NodeRef *node_; + bNodeSocket *bsocket_; + bool is_input_; + uint id_; + uint index_; + PointerRNA rna_; + Vector<SocketRef *> linked_sockets_; + Vector<SocketRef *> directly_linked_sockets_; friend NodeTreeRef; @@ -122,12 +122,12 @@ class OutputSocketRef final : public SocketRef { class NodeRef : NonCopyable, NonMovable { private: - NodeTreeRef *m_tree; - bNode *m_bnode; - PointerRNA m_rna; - uint m_id; - Vector<InputSocketRef *> m_inputs; - Vector<OutputSocketRef *> m_outputs; + NodeTreeRef *tree_; + bNode *bnode_; + PointerRNA rna_; + uint id_; + Vector<InputSocketRef *> inputs_; + Vector<OutputSocketRef *> outputs_; friend NodeTreeRef; @@ -157,13 +157,13 @@ class NodeRef : NonCopyable, NonMovable { class NodeTreeRef : NonCopyable, NonMovable { private: - LinearAllocator<> m_allocator; - bNodeTree *m_btree; - Vector<NodeRef *> m_nodes_by_id; - Vector<SocketRef *> m_sockets_by_id; - Vector<InputSocketRef *> m_input_sockets; - Vector<OutputSocketRef *> m_output_sockets; - Map<const bNodeType *, Vector<NodeRef *>> m_nodes_by_type; + LinearAllocator<> allocator_; + bNodeTree *btree_; + Vector<NodeRef *> nodes_by_id_; + Vector<SocketRef *> sockets_by_id_; + Vector<InputSocketRef *> input_sockets_; + Vector<OutputSocketRef *> output_sockets_; + Map<const bNodeType *, Vector<NodeRef *>> nodes_by_type_; public: NodeTreeRef(bNodeTree *btree); @@ -198,47 +198,47 @@ class NodeTreeRef : NonCopyable, NonMovable { inline Span<const SocketRef *> SocketRef::linked_sockets() const { - return m_linked_sockets.as_span(); + return linked_sockets_.as_span(); } inline Span<const SocketRef *> SocketRef::directly_linked_sockets() const { - return m_directly_linked_sockets.as_span(); + return directly_linked_sockets_.as_span(); } inline bool SocketRef::is_linked() const { - return m_linked_sockets.size() > 0; + return linked_sockets_.size() > 0; } inline const NodeRef &SocketRef::node() const { - return *m_node; + return *node_; } inline const NodeTreeRef &SocketRef::tree() const { - return m_node->tree(); + return node_->tree(); } inline uint SocketRef::id() const { - return m_id; + return id_; } inline uint SocketRef::index() const { - return m_index; + return index_; } inline bool SocketRef::is_input() const { - return m_is_input; + return is_input_; } inline bool SocketRef::is_output() const { - return !m_is_input; + return !is_input_; } inline const SocketRef &SocketRef::as_base() const @@ -260,32 +260,32 @@ inline const OutputSocketRef &SocketRef::as_output() const inline PointerRNA *SocketRef::rna() const { - return const_cast<PointerRNA *>(&m_rna); + return const_cast<PointerRNA *>(&rna_); } inline StringRefNull SocketRef::idname() const { - return m_bsocket->idname; + return bsocket_->idname; } inline StringRefNull SocketRef::name() const { - return m_bsocket->name; + return bsocket_->name; } inline bNodeSocket *SocketRef::bsocket() const { - return m_bsocket; + return bsocket_; } inline bNode *SocketRef::bnode() const { - return m_node->bnode(); + return node_->bnode(); } inline bNodeTree *SocketRef::btree() const { - return m_node->btree(); + return node_->btree(); } /* -------------------------------------------------------------------- @@ -294,12 +294,12 @@ inline bNodeTree *SocketRef::btree() const inline Span<const OutputSocketRef *> InputSocketRef::linked_sockets() const { - return m_linked_sockets.as_span().cast<const OutputSocketRef *>(); + return linked_sockets_.as_span().cast<const OutputSocketRef *>(); } inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() const { - return m_directly_linked_sockets.as_span().cast<const OutputSocketRef *>(); + return directly_linked_sockets_.as_span().cast<const OutputSocketRef *>(); } /* -------------------------------------------------------------------- @@ -308,12 +308,12 @@ inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() c inline Span<const InputSocketRef *> OutputSocketRef::linked_sockets() const { - return m_linked_sockets.as_span().cast<const InputSocketRef *>(); + return linked_sockets_.as_span().cast<const InputSocketRef *>(); } inline Span<const InputSocketRef *> OutputSocketRef::directly_linked_sockets() const { - return m_directly_linked_sockets.as_span().cast<const InputSocketRef *>(); + return directly_linked_sockets_.as_span().cast<const InputSocketRef *>(); } /* -------------------------------------------------------------------- @@ -322,77 +322,77 @@ inline Span<const InputSocketRef *> OutputSocketRef::directly_linked_sockets() c inline const NodeTreeRef &NodeRef::tree() const { - return *m_tree; + return *tree_; } inline Span<const InputSocketRef *> NodeRef::inputs() const { - return m_inputs.as_span(); + return inputs_.as_span(); } inline Span<const OutputSocketRef *> NodeRef::outputs() const { - return m_outputs.as_span(); + return outputs_.as_span(); } inline const InputSocketRef &NodeRef::input(uint index) const { - return *m_inputs[index]; + return *inputs_[index]; } inline const OutputSocketRef &NodeRef::output(uint index) const { - return *m_outputs[index]; + return *outputs_[index]; } inline bNode *NodeRef::bnode() const { - return m_bnode; + return bnode_; } inline bNodeTree *NodeRef::btree() const { - return m_tree->btree(); + return tree_->btree(); } inline PointerRNA *NodeRef::rna() const { - return const_cast<PointerRNA *>(&m_rna); + return const_cast<PointerRNA *>(&rna_); } inline StringRefNull NodeRef::idname() const { - return m_bnode->idname; + return bnode_->idname; } inline StringRefNull NodeRef::name() const { - return m_bnode->name; + return bnode_->name; } inline uint NodeRef::id() const { - return m_id; + return id_; } inline bool NodeRef::is_reroute_node() const { - return m_bnode->type == NODE_REROUTE; + return bnode_->type == NODE_REROUTE; } inline bool NodeRef::is_group_node() const { - return m_bnode->type == NODE_GROUP; + return bnode_->type == NODE_GROUP; } inline bool NodeRef::is_group_input_node() const { - return m_bnode->type == NODE_GROUP_INPUT; + return bnode_->type == NODE_GROUP_INPUT; } inline bool NodeRef::is_group_output_node() const { - return m_bnode->type == NODE_GROUP_OUTPUT; + return bnode_->type == NODE_GROUP_OUTPUT; } /* -------------------------------------------------------------------- @@ -401,7 +401,7 @@ inline bool NodeRef::is_group_output_node() const inline Span<const NodeRef *> NodeTreeRef::nodes() const { - return m_nodes_by_id.as_span(); + return nodes_by_id_.as_span(); } inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) const @@ -412,7 +412,7 @@ inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) co inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(const bNodeType *nodetype) const { - const Vector<NodeRef *> *nodes = m_nodes_by_type.lookup_ptr(nodetype); + const Vector<NodeRef *> *nodes = nodes_by_type_.lookup_ptr(nodetype); if (nodes == nullptr) { return {}; } @@ -423,22 +423,22 @@ inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(const bNodeType *nodetyp inline Span<const SocketRef *> NodeTreeRef::sockets() const { - return m_sockets_by_id.as_span(); + return sockets_by_id_.as_span(); } inline Span<const InputSocketRef *> NodeTreeRef::input_sockets() const { - return m_input_sockets.as_span(); + return input_sockets_.as_span(); } inline Span<const OutputSocketRef *> NodeTreeRef::output_sockets() const { - return m_output_sockets.as_span(); + return output_sockets_.as_span(); } inline bNodeTree *NodeTreeRef::btree() const { - return m_btree; + return btree_; } } // namespace bke diff --git a/source/blender/blenkernel/intern/derived_node_tree.cc b/source/blender/blenkernel/intern/derived_node_tree.cc index b53457812ba..83ef45189bc 100644 --- a/source/blender/blenkernel/intern/derived_node_tree.cc +++ b/source/blender/blenkernel/intern/derived_node_tree.cc @@ -29,7 +29,7 @@ static const NodeTreeRef &get_tree_ref(NodeTreeRefMap &node_tree_refs, bNodeTree [&]() { return std::make_unique<NodeTreeRef>(btree); }); } -DerivedNodeTree::DerivedNodeTree(bNodeTree *btree, NodeTreeRefMap &node_tree_refs) : m_btree(btree) +DerivedNodeTree::DerivedNodeTree(bNodeTree *btree, NodeTreeRefMap &node_tree_refs) : btree_(btree) { const NodeTreeRef &main_tree_ref = get_tree_ref(node_tree_refs, btree); @@ -63,8 +63,8 @@ BLI_NOINLINE void DerivedNodeTree::insert_nodes_and_links_in_id_order(const Node DInputSocket *to_socket = (DInputSocket *)sockets_map[to_socket_ref->id()]; for (const OutputSocketRef *from_socket_ref : to_socket_ref->linked_sockets()) { DOutputSocket *from_socket = (DOutputSocket *)sockets_map[from_socket_ref->id()]; - to_socket->m_linked_sockets.append(from_socket); - from_socket->m_linked_sockets.append(to_socket); + to_socket->linked_sockets_.append(from_socket); + from_socket->linked_sockets_.append(to_socket); } } } @@ -74,34 +74,34 @@ DNode &DerivedNodeTree::create_node(const NodeRef &node_ref, DParentNode *parent, MutableSpan<DSocket *> r_sockets_map) { - DNode &node = *m_allocator.construct<DNode>(); - node.m_node_ref = &node_ref; - node.m_parent = parent; - node.m_id = UNINITIALIZED_ID; + DNode &node = *allocator_.construct<DNode>(); + node.node_ref_ = &node_ref; + node.parent_ = parent; + node.id_ = UNINITIALIZED_ID; - node.m_inputs = m_allocator.construct_elements_and_pointer_array<DInputSocket>( + node.inputs_ = allocator_.construct_elements_and_pointer_array<DInputSocket>( node_ref.inputs().size()); - node.m_outputs = m_allocator.construct_elements_and_pointer_array<DOutputSocket>( + node.outputs_ = allocator_.construct_elements_and_pointer_array<DOutputSocket>( node_ref.outputs().size()); - for (uint i : node.m_inputs.index_range()) { + for (uint i : node.inputs_.index_range()) { const InputSocketRef &socket_ref = node_ref.input(i); - DInputSocket &socket = *node.m_inputs[i]; + DInputSocket &socket = *node.inputs_[i]; - socket.m_id = UNINITIALIZED_ID; - socket.m_node = &node; - socket.m_socket_ref = &socket_ref; + socket.id_ = UNINITIALIZED_ID; + socket.node_ = &node; + socket.socket_ref_ = &socket_ref; r_sockets_map[socket_ref.id()] = &socket; } - for (uint i : node.m_outputs.index_range()) { + for (uint i : node.outputs_.index_range()) { const OutputSocketRef &socket_ref = node_ref.output(i); - DOutputSocket &socket = *node.m_outputs[i]; + DOutputSocket &socket = *node.outputs_[i]; - socket.m_id = UNINITIALIZED_ID; - socket.m_node = &node; - socket.m_socket_ref = &socket_ref; + socket.id_ = UNINITIALIZED_ID; + socket.node_ = &node; + socket.socket_ref_ = &socket_ref; r_sockets_map[socket_ref.id()] = &socket; } @@ -116,7 +116,7 @@ BLI_NOINLINE void DerivedNodeTree::expand_groups(Vector<DNode *> &all_nodes, { for (uint i = 0; i < all_nodes.size(); i++) { DNode &node = *all_nodes[i]; - if (node.m_node_ref->is_group_node()) { + if (node.node_ref_->is_group_node()) { this->expand_group_node(node, all_nodes, all_group_inputs, all_parent_nodes, node_tree_refs); } } @@ -128,7 +128,7 @@ BLI_NOINLINE void DerivedNodeTree::expand_group_node(DNode &group_node, Vector<DParentNode *> &all_parent_nodes, NodeTreeRefMap &node_tree_refs) { - const NodeRef &group_node_ref = *group_node.m_node_ref; + const NodeRef &group_node_ref = *group_node.node_ref_; BLI_assert(group_node_ref.is_group_node()); bNodeTree *btree = (bNodeTree *)group_node_ref.bnode()->id; @@ -138,10 +138,10 @@ BLI_NOINLINE void DerivedNodeTree::expand_group_node(DNode &group_node, const NodeTreeRef &group_ref = get_tree_ref(node_tree_refs, btree); - DParentNode &parent = *m_allocator.construct<DParentNode>(); - parent.m_id = all_parent_nodes.append_and_get_index(&parent); - parent.m_parent = group_node.m_parent; - parent.m_node_ref = &group_node_ref; + DParentNode &parent = *allocator_.construct<DParentNode>(); + parent.id_ = all_parent_nodes.append_and_get_index(&parent); + parent.parent_ = group_node.parent_; + parent.node_ref_ = &group_node_ref; this->insert_nodes_and_links_in_id_order(group_ref, &parent, all_nodes); Span<DNode *> new_nodes_by_id = all_nodes.as_span().take_back(group_ref.nodes().size()); @@ -154,18 +154,18 @@ BLI_NOINLINE void DerivedNodeTree::expand_group_node(DNode &group_node, BLI_NOINLINE void DerivedNodeTree::create_group_inputs_for_unlinked_inputs( DNode &node, Vector<DGroupInput *> &all_group_inputs) { - for (DInputSocket *input_socket : node.m_inputs) { + for (DInputSocket *input_socket : node.inputs_) { if (input_socket->is_linked()) { continue; } - DGroupInput &group_input = *m_allocator.construct<DGroupInput>(); - group_input.m_id = UNINITIALIZED_ID; - group_input.m_socket_ref = &input_socket->socket_ref(); - group_input.m_parent = node.m_parent; + DGroupInput &group_input = *allocator_.construct<DGroupInput>(); + group_input.id_ = UNINITIALIZED_ID; + group_input.socket_ref_ = &input_socket->socket_ref(); + group_input.parent_ = node.parent_; - group_input.m_linked_sockets.append(input_socket); - input_socket->m_linked_group_inputs.append(&group_input); + group_input.linked_sockets_.append(input_socket); + input_socket->linked_group_inputs_.append(&group_input); all_group_inputs.append(&group_input); } } @@ -186,34 +186,34 @@ BLI_NOINLINE void DerivedNodeTree::relink_group_inputs(const NodeTreeRef &group_ BLI_assert(input_amount == input_node_ref.outputs().size() - 1); for (uint input_index : IndexRange(input_amount)) { - DInputSocket *outside_group = group_node.m_inputs[input_index]; - DOutputSocket *inside_group = input_node.m_outputs[input_index]; + DInputSocket *outside_group = group_node.inputs_[input_index]; + DOutputSocket *inside_group = input_node.outputs_[input_index]; - for (DOutputSocket *outside_connected : outside_group->m_linked_sockets) { - outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(outside_group); + for (DOutputSocket *outside_connected : outside_group->linked_sockets_) { + outside_connected->linked_sockets_.remove_first_occurrence_and_reorder(outside_group); } - for (DGroupInput *outside_connected : outside_group->m_linked_group_inputs) { - outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(outside_group); + for (DGroupInput *outside_connected : outside_group->linked_group_inputs_) { + outside_connected->linked_sockets_.remove_first_occurrence_and_reorder(outside_group); } - for (DInputSocket *inside_connected : inside_group->m_linked_sockets) { - inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(inside_group); + for (DInputSocket *inside_connected : inside_group->linked_sockets_) { + inside_connected->linked_sockets_.remove_first_occurrence_and_reorder(inside_group); - for (DOutputSocket *outside_connected : outside_group->m_linked_sockets) { - inside_connected->m_linked_sockets.append(outside_connected); - outside_connected->m_linked_sockets.append(inside_connected); + for (DOutputSocket *outside_connected : outside_group->linked_sockets_) { + inside_connected->linked_sockets_.append(outside_connected); + outside_connected->linked_sockets_.append(inside_connected); } - for (DGroupInput *outside_connected : outside_group->m_linked_group_inputs) { - inside_connected->m_linked_group_inputs.append(outside_connected); - outside_connected->m_linked_sockets.append(inside_connected); + for (DGroupInput *outside_connected : outside_group->linked_group_inputs_) { + inside_connected->linked_group_inputs_.append(outside_connected); + outside_connected->linked_sockets_.append(inside_connected); } } - inside_group->m_linked_sockets.clear(); - outside_group->m_linked_sockets.clear(); - outside_group->m_linked_group_inputs.clear(); + inside_group->linked_sockets_.clear(); + outside_group->linked_sockets_.clear(); + outside_group->linked_group_inputs_.clear(); } } @@ -233,33 +233,33 @@ BLI_NOINLINE void DerivedNodeTree::relink_group_outputs(const NodeTreeRef &group BLI_assert(output_amount == output_node_ref.inputs().size() - 1); for (uint output_index : IndexRange(output_amount)) { - DOutputSocket *outside_group = group_node.m_outputs[output_index]; - DInputSocket *inside_group = output_node.m_inputs[output_index]; + DOutputSocket *outside_group = group_node.outputs_[output_index]; + DInputSocket *inside_group = output_node.inputs_[output_index]; - for (DInputSocket *outside_connected : outside_group->m_linked_sockets) { - outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(outside_group); + for (DInputSocket *outside_connected : outside_group->linked_sockets_) { + outside_connected->linked_sockets_.remove_first_occurrence_and_reorder(outside_group); } - for (DOutputSocket *inside_connected : inside_group->m_linked_sockets) { - inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(inside_group); + for (DOutputSocket *inside_connected : inside_group->linked_sockets_) { + inside_connected->linked_sockets_.remove_first_occurrence_and_reorder(inside_group); - for (DInputSocket *outside_connected : outside_group->m_linked_sockets) { - inside_connected->m_linked_sockets.append(outside_connected); - outside_connected->m_linked_sockets.append(inside_connected); + for (DInputSocket *outside_connected : outside_group->linked_sockets_) { + inside_connected->linked_sockets_.append(outside_connected); + outside_connected->linked_sockets_.append(inside_connected); } } - for (DGroupInput *inside_connected : inside_group->m_linked_group_inputs) { - inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(inside_group); + for (DGroupInput *inside_connected : inside_group->linked_group_inputs_) { + inside_connected->linked_sockets_.remove_first_occurrence_and_reorder(inside_group); - for (DInputSocket *outside_connected : outside_group->m_linked_sockets) { - inside_connected->m_linked_sockets.append(outside_connected); - outside_connected->m_linked_group_inputs.append(inside_connected); + for (DInputSocket *outside_connected : outside_group->linked_sockets_) { + inside_connected->linked_sockets_.append(outside_connected); + outside_connected->linked_group_inputs_.append(inside_connected); } } - outside_group->m_linked_sockets.clear(); - inside_group->m_linked_sockets.clear(); + outside_group->linked_sockets_.clear(); + inside_group->linked_sockets_.clear(); } } @@ -268,9 +268,9 @@ BLI_NOINLINE void DerivedNodeTree::remove_expanded_group_interfaces(Vector<DNode int index = 0; while (index < all_nodes.size()) { DNode &node = *all_nodes[index]; - const NodeRef &node_ref = *node.m_node_ref; + const NodeRef &node_ref = *node.node_ref_; if (node_ref.is_group_node() || - (node.m_parent != nullptr && + (node.parent_ != nullptr && (node_ref.is_group_input_node() || node_ref.is_group_output_node()))) { all_nodes.remove_and_reorder(index); node.destruct_with_sockets(); @@ -287,7 +287,7 @@ BLI_NOINLINE void DerivedNodeTree::remove_unused_group_inputs( int index = 0; while (index < all_group_inputs.size()) { DGroupInput &group_input = *all_group_inputs[index]; - if (group_input.m_linked_sockets.is_empty()) { + if (group_input.linked_sockets_.is_empty()) { all_group_inputs.remove_and_reorder(index); group_input.~DGroupInput(); } @@ -299,10 +299,10 @@ BLI_NOINLINE void DerivedNodeTree::remove_unused_group_inputs( void DNode::destruct_with_sockets() { - for (DInputSocket *socket : m_inputs) { + for (DInputSocket *socket : inputs_) { socket->~DInputSocket(); } - for (DOutputSocket *socket : m_outputs) { + for (DOutputSocket *socket : outputs_) { socket->~DOutputSocket(); } this->~DNode(); @@ -313,47 +313,47 @@ BLI_NOINLINE void DerivedNodeTree::store_in_this_and_init_ids( Vector<DGroupInput *> &&all_group_inputs, Vector<DParentNode *> &&all_parent_nodes) { - m_nodes_by_id = std::move(all_nodes); - m_group_inputs = std::move(all_group_inputs); - m_parent_nodes = std::move(all_parent_nodes); + nodes_by_id_ = std::move(all_nodes); + group_inputs_ = std::move(all_group_inputs); + parent_nodes_ = std::move(all_parent_nodes); - for (uint node_index : m_nodes_by_id.index_range()) { - DNode *node = m_nodes_by_id[node_index]; - node->m_id = node_index; + for (uint node_index : nodes_by_id_.index_range()) { + DNode *node = nodes_by_id_[node_index]; + node->id_ = node_index; - const bNodeType *nodetype = node->m_node_ref->bnode()->typeinfo; - m_nodes_by_type.lookup_or_add_default(nodetype).append(node); + const bNodeType *nodetype = node->node_ref_->bnode()->typeinfo; + nodes_by_type_.lookup_or_add_default(nodetype).append(node); - for (DInputSocket *socket : node->m_inputs) { - socket->m_id = m_sockets_by_id.append_and_get_index(socket); - m_input_sockets.append(socket); + for (DInputSocket *socket : node->inputs_) { + socket->id_ = sockets_by_id_.append_and_get_index(socket); + input_sockets_.append(socket); } - for (DOutputSocket *socket : node->m_outputs) { - socket->m_id = m_sockets_by_id.append_and_get_index(socket); - m_output_sockets.append(socket); + for (DOutputSocket *socket : node->outputs_) { + socket->id_ = sockets_by_id_.append_and_get_index(socket); + output_sockets_.append(socket); } } - for (uint i : m_group_inputs.index_range()) { - m_group_inputs[i]->m_id = i; + for (uint i : group_inputs_.index_range()) { + group_inputs_[i]->id_ = i; } } DerivedNodeTree::~DerivedNodeTree() { - for (DInputSocket *socket : m_input_sockets) { + for (DInputSocket *socket : input_sockets_) { socket->~DInputSocket(); } - for (DOutputSocket *socket : m_output_sockets) { + for (DOutputSocket *socket : output_sockets_) { socket->~DOutputSocket(); } - for (DNode *node : m_nodes_by_id) { + for (DNode *node : nodes_by_id_) { node->~DNode(); } - for (DGroupInput *group_input : m_group_inputs) { + for (DGroupInput *group_input : group_inputs_) { group_input->~DGroupInput(); } - for (DParentNode *parent : m_parent_nodes) { + for (DParentNode *parent : parent_nodes_) { parent->~DParentNode(); } } @@ -384,7 +384,7 @@ std::string DerivedNodeTree::to_dot() const Map<const DGroupInput *, dot::NodeWithSocketsRef> dot_group_inputs; Map<const DParentNode *, dot::Cluster *> dot_clusters; - for (const DNode *node : m_nodes_by_id) { + for (const DNode *node : nodes_by_id_) { dot::Node &dot_node = digraph.new_node(""); dot_node.set_background_color("white"); @@ -404,7 +404,7 @@ std::string DerivedNodeTree::to_dot() const dot_node.set_parent_cluster(cluster); } - for (const DGroupInput *group_input : m_group_inputs) { + for (const DGroupInput *group_input : group_inputs_) { dot::Node &dot_node = digraph.new_node(""); dot_node.set_background_color("white"); @@ -416,7 +416,7 @@ std::string DerivedNodeTree::to_dot() const dot_node.set_parent_cluster(cluster); } - for (const DNode *to_node : m_nodes_by_id) { + for (const DNode *to_node : nodes_by_id_) { dot::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(to_node); for (const DInputSocket *to_socket : to_node->inputs()) { diff --git a/source/blender/blenkernel/intern/node_tree_ref.cc b/source/blender/blenkernel/intern/node_tree_ref.cc index 6bd3e2d2e5a..1803243d4cc 100644 --- a/source/blender/blenkernel/intern/node_tree_ref.cc +++ b/source/blender/blenkernel/intern/node_tree_ref.cc @@ -21,40 +21,40 @@ namespace blender { namespace bke { -NodeTreeRef::NodeTreeRef(bNodeTree *btree) : m_btree(btree) +NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree) { Map<bNode *, NodeRef *> node_mapping; LISTBASE_FOREACH (bNode *, bnode, &btree->nodes) { - NodeRef &node = *m_allocator.construct<NodeRef>(); + NodeRef &node = *allocator_.construct<NodeRef>(); - node.m_tree = this; - node.m_bnode = bnode; - node.m_id = m_nodes_by_id.append_and_get_index(&node); - RNA_pointer_create(&btree->id, &RNA_Node, bnode, &node.m_rna); + node.tree_ = this; + node.bnode_ = bnode; + node.id_ = nodes_by_id_.append_and_get_index(&node); + RNA_pointer_create(&btree->id, &RNA_Node, bnode, &node.rna_); LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->inputs) { - InputSocketRef &socket = *m_allocator.construct<InputSocketRef>(); - socket.m_node = &node; - socket.m_index = node.m_inputs.append_and_get_index(&socket); - socket.m_is_input = true; - socket.m_bsocket = bsocket; - socket.m_id = m_sockets_by_id.append_and_get_index(&socket); - RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.m_rna); + InputSocketRef &socket = *allocator_.construct<InputSocketRef>(); + socket.node_ = &node; + socket.index_ = node.inputs_.append_and_get_index(&socket); + socket.is_input_ = true; + socket.bsocket_ = bsocket; + socket.id_ = sockets_by_id_.append_and_get_index(&socket); + RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.rna_); } LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->outputs) { - OutputSocketRef &socket = *m_allocator.construct<OutputSocketRef>(); - socket.m_node = &node; - socket.m_index = node.m_outputs.append_and_get_index(&socket); - socket.m_is_input = false; - socket.m_bsocket = bsocket; - socket.m_id = m_sockets_by_id.append_and_get_index(&socket); - RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.m_rna); + OutputSocketRef &socket = *allocator_.construct<OutputSocketRef>(); + socket.node_ = &node; + socket.index_ = node.outputs_.append_and_get_index(&socket); + socket.is_input_ = false; + socket.bsocket_ = bsocket; + socket.id_ = sockets_by_id_.append_and_get_index(&socket); + RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.rna_); } - m_input_sockets.extend(node.m_inputs); - m_output_sockets.extend(node.m_outputs); + input_sockets_.extend(node.inputs_); + output_sockets_.extend(node.outputs_); node_mapping.add_new(bnode, &node); } @@ -65,34 +65,34 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : m_btree(btree) InputSocketRef &to_socket = this->find_input_socket( node_mapping, blink->tonode, blink->tosock); - from_socket.m_directly_linked_sockets.append(&to_socket); - to_socket.m_directly_linked_sockets.append(&from_socket); + from_socket.directly_linked_sockets_.append(&to_socket); + to_socket.directly_linked_sockets_.append(&from_socket); } - for (OutputSocketRef *socket : m_output_sockets) { - if (!socket->m_node->is_reroute_node()) { - this->find_targets_skipping_reroutes(*socket, socket->m_linked_sockets); - for (SocketRef *target : socket->m_linked_sockets) { - target->m_linked_sockets.append(socket); + for (OutputSocketRef *socket : output_sockets_) { + if (!socket->node_->is_reroute_node()) { + this->find_targets_skipping_reroutes(*socket, socket->linked_sockets_); + for (SocketRef *target : socket->linked_sockets_) { + target->linked_sockets_.append(socket); } } } - for (NodeRef *node : m_nodes_by_id) { - const bNodeType *nodetype = node->m_bnode->typeinfo; - m_nodes_by_type.lookup_or_add_default(nodetype).append(node); + for (NodeRef *node : nodes_by_id_) { + const bNodeType *nodetype = node->bnode_->typeinfo; + nodes_by_type_.lookup_or_add_default(nodetype).append(node); } } NodeTreeRef::~NodeTreeRef() { - for (NodeRef *node : m_nodes_by_id) { + for (NodeRef *node : nodes_by_id_) { node->~NodeRef(); } - for (InputSocketRef *socket : m_input_sockets) { + for (InputSocketRef *socket : input_sockets_) { socket->~InputSocketRef(); } - for (OutputSocketRef *socket : m_output_sockets) { + for (OutputSocketRef *socket : output_sockets_) { socket->~OutputSocketRef(); } } @@ -102,13 +102,13 @@ InputSocketRef &NodeTreeRef::find_input_socket(Map<bNode *, NodeRef *> &node_map bNodeSocket *bsocket) { NodeRef *node = node_mapping.lookup(bnode); - for (SocketRef *socket : node->m_inputs) { - if (socket->m_bsocket == bsocket) { + for (SocketRef *socket : node->inputs_) { + if (socket->bsocket_ == bsocket) { return *(InputSocketRef *)socket; } } BLI_assert(false); - return *node->m_inputs[0]; + return *node->inputs_[0]; } OutputSocketRef &NodeTreeRef::find_output_socket(Map<bNode *, NodeRef *> &node_mapping, @@ -116,21 +116,21 @@ OutputSocketRef &NodeTreeRef::find_output_socket(Map<bNode *, NodeRef *> &node_m bNodeSocket *bsocket) { NodeRef *node = node_mapping.lookup(bnode); - for (SocketRef *socket : node->m_outputs) { - if (socket->m_bsocket == bsocket) { + for (SocketRef *socket : node->outputs_) { + if (socket->bsocket_ == bsocket) { return *(OutputSocketRef *)socket; } } BLI_assert(false); - return *node->m_outputs[0]; + return *node->outputs_[0]; } void NodeTreeRef::find_targets_skipping_reroutes(OutputSocketRef &socket, Vector<SocketRef *> &r_targets) { - for (SocketRef *direct_target : socket.m_directly_linked_sockets) { - if (direct_target->m_node->is_reroute_node()) { - this->find_targets_skipping_reroutes(*direct_target->m_node->m_outputs[0], r_targets); + for (SocketRef *direct_target : socket.directly_linked_sockets_) { + if (direct_target->node_->is_reroute_node()) { + this->find_targets_skipping_reroutes(*direct_target->node_->outputs_[0], r_targets); } else { r_targets.append_non_duplicates(direct_target); @@ -145,7 +145,7 @@ std::string NodeTreeRef::to_dot() const Map<const NodeRef *, dot::NodeWithSocketsRef> dot_nodes; - for (const NodeRef *node : m_nodes_by_id) { + for (const NodeRef *node : nodes_by_id_) { dot::Node &dot_node = digraph.new_node(""); dot_node.set_background_color("white"); @@ -162,7 +162,7 @@ std::string NodeTreeRef::to_dot() const dot::NodeWithSocketsRef(dot_node, node->name(), input_names, output_names)); } - for (const OutputSocketRef *from_socket : m_output_sockets) { + for (const OutputSocketRef *from_socket : output_sockets_) { for (const InputSocketRef *to_socket : from_socket->directly_linked_sockets()) { dot::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(&from_socket->node()); dot::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(&to_socket->node()); diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh index 25267bc65d6..8569d3d1af8 100644 --- a/source/blender/blenlib/BLI_array.hh +++ b/source/blender/blenlib/BLI_array.hh @@ -65,16 +65,16 @@ template< class Array { private: /** The beginning of the array. It might point into the inline buffer. */ - T *m_data; + T *data_; /** Number of elements in the array. */ - uint m_size; + uint size_; /** Used for allocations when the inline buffer is too small. */ - Allocator m_allocator; + Allocator allocator_; /** A placeholder buffer that will remain uninitialized until it is used. */ - AlignedBuffer<sizeof(T) * InlineBufferCapacity, alignof(T)> m_inline_buffer; + AlignedBuffer<sizeof(T) * InlineBufferCapacity, alignof(T)> inline_buffer_; public: /** @@ -82,8 +82,8 @@ class Array { */ Array() { - m_data = this->inline_buffer(); - m_size = 0; + data_ = this->inline_buffer(); + size_ = 0; } /** @@ -91,9 +91,9 @@ class Array { */ Array(Span<T> values) { - m_size = values.size(); - m_data = this->get_buffer_for_size(values.size()); - uninitialized_copy_n(values.data(), m_size, m_data); + size_ = values.size(); + data_ = this->get_buffer_for_size(values.size()); + uninitialized_copy_n(values.data(), size_, data_); } /** @@ -113,9 +113,9 @@ class Array { */ explicit Array(uint size) { - m_size = size; - m_data = this->get_buffer_for_size(size); - default_construct_n(m_data, size); + size_ = size; + data_ = this->get_buffer_for_size(size); + default_construct_n(data_, size); } /** @@ -124,9 +124,9 @@ class Array { */ Array(uint size, const T &value) { - m_size = size; - m_data = this->get_buffer_for_size(size); - uninitialized_fill_n(m_data, m_size, value); + size_ = size; + data_ = this->get_buffer_for_size(size); + uninitialized_fill_n(data_, size_, value); } /** @@ -143,39 +143,39 @@ class Array { */ Array(uint size, NoInitialization) { - m_size = size; - m_data = this->get_buffer_for_size(size); + size_ = size; + data_ = this->get_buffer_for_size(size); } - Array(const Array &other) : m_allocator(other.m_allocator) + Array(const Array &other) : allocator_(other.allocator_) { - m_size = other.size(); + size_ = other.size(); - m_data = this->get_buffer_for_size(other.size()); - uninitialized_copy_n(other.data(), m_size, m_data); + data_ = this->get_buffer_for_size(other.size()); + uninitialized_copy_n(other.data(), size_, data_); } - Array(Array &&other) noexcept : m_allocator(other.m_allocator) + Array(Array &&other) noexcept : allocator_(other.allocator_) { - m_size = other.m_size; + size_ = other.size_; if (!other.uses_inline_buffer()) { - m_data = other.m_data; + data_ = other.data_; } else { - m_data = this->get_buffer_for_size(m_size); - uninitialized_relocate_n(other.m_data, m_size, m_data); + data_ = this->get_buffer_for_size(size_); + uninitialized_relocate_n(other.data_, size_, data_); } - other.m_data = other.inline_buffer(); - other.m_size = 0; + other.data_ = other.inline_buffer(); + other.size_ = 0; } ~Array() { - destruct_n(m_data, m_size); + destruct_n(data_, size_); if (!this->uses_inline_buffer()) { - m_allocator.deallocate((void *)m_data); + allocator_.deallocate((void *)data_); } } @@ -203,12 +203,12 @@ class Array { operator Span<T>() const { - return Span<T>(m_data, m_size); + return Span<T>(data_, size_); } operator MutableSpan<T>() { - return MutableSpan<T>(m_data, m_size); + return MutableSpan<T>(data_, size_); } Span<T> as_span() const @@ -223,14 +223,14 @@ class Array { T &operator[](uint index) { - BLI_assert(index < m_size); - return m_data[index]; + BLI_assert(index < size_); + return data_[index]; } const T &operator[](uint index) const { - BLI_assert(index < m_size); - return m_data[index]; + BLI_assert(index < size_); + return data_[index]; } /** @@ -238,7 +238,7 @@ class Array { */ uint size() const { - return m_size; + return size_; } /** @@ -246,7 +246,7 @@ class Array { */ bool is_empty() const { - return m_size == 0; + return size_ == 0; } /** @@ -254,7 +254,7 @@ class Array { */ void fill(const T &value) { - initialized_fill_n(m_data, m_size, value); + initialized_fill_n(data_, size_, value); } /** @@ -270,31 +270,31 @@ class Array { */ const T *data() const { - return m_data; + return data_; } T *data() { - return m_data; + return data_; } const T *begin() const { - return m_data; + return data_; } const T *end() const { - return m_data + m_size; + return data_ + size_; } T *begin() { - return m_data; + return data_; } T *end() { - return m_data + m_size; + return data_ + size_; } /** @@ -302,7 +302,7 @@ class Array { */ IndexRange index_range() const { - return IndexRange(m_size); + return IndexRange(size_); } /** @@ -311,7 +311,7 @@ class Array { */ void clear_without_destruct() { - m_size = 0; + size_ = 0; } /** @@ -319,7 +319,7 @@ class Array { */ Allocator &allocator() { - return m_allocator; + return allocator_; } /** @@ -344,17 +344,17 @@ class Array { T *inline_buffer() const { - return (T *)m_inline_buffer.ptr(); + return (T *)inline_buffer_.ptr(); } T *allocate(uint size) { - return (T *)m_allocator.allocate(size * sizeof(T), alignof(T), AT); + return (T *)allocator_.allocate(size * sizeof(T), alignof(T), AT); } bool uses_inline_buffer() const { - return m_data == this->inline_buffer(); + return data_ == this->inline_buffer(); } }; diff --git a/source/blender/blenlib/BLI_dot_export.hh b/source/blender/blenlib/BLI_dot_export.hh index b496c00a75d..bad7e4c57a8 100644 --- a/source/blender/blenlib/BLI_dot_export.hh +++ b/source/blender/blenlib/BLI_dot_export.hh @@ -49,25 +49,25 @@ class AttributeList; class AttributeList { private: - Map<std::string, std::string> m_attributes; + Map<std::string, std::string> attributes_; public: void export__as_bracket_list(std::stringstream &ss) const; void set(StringRef key, StringRef value) { - m_attributes.add_overwrite(key, value); + attributes_.add_overwrite(key, value); } }; class Graph { private: - AttributeList m_attributes; - Vector<std::unique_ptr<Node>> m_nodes; - Vector<std::unique_ptr<Cluster>> m_clusters; + AttributeList attributes_; + Vector<std::unique_ptr<Node>> nodes_; + Vector<std::unique_ptr<Cluster>> clusters_; - Set<Node *> m_top_level_nodes; - Set<Cluster *> m_top_level_clusters; + Set<Node *> top_level_nodes_; + Set<Cluster *> top_level_clusters_; friend Cluster; friend Node; @@ -80,7 +80,7 @@ class Graph { void set_attribute(StringRef key, StringRef value) { - m_attributes.set(key, value); + attributes_.set(key, value); } void set_rankdir(Attr_rankdir rankdir) @@ -93,16 +93,16 @@ class Graph { class Cluster { private: - AttributeList m_attributes; - Graph &m_graph; - Cluster *m_parent = nullptr; - Set<Cluster *> m_children; - Set<Node *> m_nodes; + AttributeList attributes_; + Graph &graph_; + Cluster *parent_ = nullptr; + Set<Cluster *> children_; + Set<Node *> nodes_; friend Graph; friend Node; - Cluster(Graph &graph) : m_graph(graph) + Cluster(Graph &graph) : graph_(graph) { } @@ -111,7 +111,7 @@ class Cluster { void set_attribute(StringRef key, StringRef value) { - m_attributes.set(key, value); + attributes_.set(key, value); } void set_parent_cluster(Cluster *cluster); @@ -125,25 +125,25 @@ class Cluster { class Node { private: - AttributeList m_attributes; - Graph &m_graph; - Cluster *m_cluster = nullptr; + AttributeList attributes_; + Graph &graph_; + Cluster *cluster_ = nullptr; friend Graph; - Node(Graph &graph) : m_graph(graph) + Node(Graph &graph) : graph_(graph) { } public: const AttributeList &attributes() const { - return m_attributes; + return attributes_; } AttributeList &attributes() { - return m_attributes; + return attributes_; } void set_parent_cluster(Cluster *cluster); @@ -154,7 +154,7 @@ class Node { void set_attribute(StringRef key, StringRef value) { - m_attributes.set(key, value); + attributes_.set(key, value); } void set_shape(Attr_shape shape) @@ -176,7 +176,7 @@ class Node { class UndirectedGraph final : public Graph { private: - Vector<std::unique_ptr<UndirectedEdge>> m_edges; + Vector<std::unique_ptr<UndirectedEdge>> edges_; public: std::string to_dot_string() const; @@ -186,7 +186,7 @@ class UndirectedGraph final : public Graph { class DirectedGraph final : public Graph { private: - Vector<std::unique_ptr<DirectedEdge>> m_edges; + Vector<std::unique_ptr<DirectedEdge>> edges_; public: std::string to_dot_string() const; @@ -196,12 +196,12 @@ class DirectedGraph final : public Graph { class NodePort { private: - Node *m_node; - std::optional<std::string> m_port_name; + Node *node_; + std::optional<std::string> port_name_; public: NodePort(Node &node, std::optional<std::string> port_name = {}) - : m_node(&node), m_port_name(std::move(port_name)) + : node_(&node), port_name_(std::move(port_name)) { } @@ -210,18 +210,18 @@ class NodePort { class Edge : blender::NonCopyable, blender::NonMovable { protected: - AttributeList m_attributes; - NodePort m_a; - NodePort m_b; + AttributeList attributes_; + NodePort a_; + NodePort b_; public: - Edge(NodePort a, NodePort b) : m_a(std::move(a)), m_b(std::move(b)) + Edge(NodePort a, NodePort b) : a_(std::move(a)), b_(std::move(b)) { } void set_attribute(StringRef key, StringRef value) { - m_attributes.set(key, value); + attributes_.set(key, value); } void set_arrowhead(Attr_arrowType type) @@ -262,7 +262,7 @@ std::string color_attr_from_hsv(float h, float s, float v); class NodeWithSocketsRef { private: - Node *m_node; + Node *node_; public: NodeWithSocketsRef(Node &node, @@ -273,13 +273,13 @@ class NodeWithSocketsRef { NodePort input(uint index) const { std::string port = "\"in" + std::to_string(index) + "\""; - return NodePort(*m_node, port); + return NodePort(*node_, port); } NodePort output(uint index) const { std::string port = "\"out" + std::to_string(index) + "\""; - return NodePort(*m_node, port); + return NodePort(*node_, port); } }; diff --git a/source/blender/blenlib/BLI_hash_tables.hh b/source/blender/blenlib/BLI_hash_tables.hh index 195811ebd71..51818ecada6 100644 --- a/source/blender/blenlib/BLI_hash_tables.hh +++ b/source/blender/blenlib/BLI_hash_tables.hh @@ -109,12 +109,12 @@ inline constexpr uint32_t total_slot_amount_for_usable_slots(uint32_t min_usable class LoadFactor { private: - uint8_t m_numerator; - uint8_t m_denominator; + uint8_t numerator_; + uint8_t denominator_; public: LoadFactor(uint8_t numerator, uint8_t denominator) - : m_numerator(numerator), m_denominator(denominator) + : numerator_(numerator), denominator_(denominator) { BLI_assert(numerator > 0); BLI_assert(numerator < denominator); @@ -127,10 +127,10 @@ class LoadFactor { { BLI_assert(is_power_of_2_i((int)min_total_slots)); - uint32_t total_slots = this->compute_total_slots(min_usable_slots, m_numerator, m_denominator); + uint32_t total_slots = this->compute_total_slots(min_usable_slots, numerator_, denominator_); total_slots = std::max(total_slots, min_total_slots); uint32_t usable_slots = floor_multiplication_with_fraction( - total_slots, m_numerator, m_denominator); + total_slots, numerator_, denominator_); BLI_assert(min_usable_slots <= usable_slots); *r_total_slots = total_slots; @@ -261,17 +261,17 @@ template<typename Pointer> struct PointerKeyInfo { class HashTableStats { private: - Vector<uint32_t> m_keys_by_collision_count; - uint32_t m_total_collisions; - float m_average_collisions; - uint32_t m_size; - uint32_t m_capacity; - uint32_t m_removed_amount; - float m_load_factor; - float m_removed_load_factor; - uint32_t m_size_per_element; - uint32_t m_size_in_bytes; - const void *m_address; + Vector<uint32_t> keys_by_collision_count_; + uint32_t total_collisions_; + float average_collisions_; + uint32_t size_; + uint32_t capacity_; + uint32_t removed_amount_; + float load_factor_; + float removed_load_factor_; + uint32_t size_per_element_; + uint32_t size_in_bytes_; + const void *address_; public: /** @@ -286,47 +286,47 @@ class HashTableStats { template<typename HashTable, typename Keys> HashTableStats(const HashTable &hash_table, const Keys &keys) { - m_total_collisions = 0; - m_size = hash_table.size(); - m_capacity = hash_table.capacity(); - m_removed_amount = hash_table.removed_amount(); - m_size_per_element = hash_table.size_per_element(); - m_size_in_bytes = hash_table.size_in_bytes(); - m_address = (const void *)&hash_table; + total_collisions_ = 0; + size_ = hash_table.size(); + capacity_ = hash_table.capacity(); + removed_amount_ = hash_table.removed_amount(); + size_per_element_ = hash_table.size_per_element(); + size_in_bytes_ = hash_table.size_in_bytes(); + address_ = (const void *)&hash_table; for (const auto &key : keys) { uint32_t collisions = hash_table.count_collisions(key); - if (m_keys_by_collision_count.size() <= collisions) { - m_keys_by_collision_count.append_n_times( - 0, collisions - m_keys_by_collision_count.size() + 1); + if (keys_by_collision_count_.size() <= collisions) { + keys_by_collision_count_.append_n_times(0, + collisions - keys_by_collision_count_.size() + 1); } - m_keys_by_collision_count[collisions]++; - m_total_collisions += collisions; + keys_by_collision_count_[collisions]++; + total_collisions_ += collisions; } - m_average_collisions = (m_size == 0) ? 0 : (float)m_total_collisions / (float)m_size; - m_load_factor = (float)m_size / (float)m_capacity; - m_removed_load_factor = (float)m_removed_amount / (float)m_capacity; + average_collisions_ = (size_ == 0) ? 0 : (float)total_collisions_ / (float)size_; + load_factor_ = (float)size_ / (float)capacity_; + removed_load_factor_ = (float)removed_amount_ / (float)capacity_; } void print(StringRef name = "") { std::cout << "Hash Table Stats: " << name << "\n"; - std::cout << " Address: " << m_address << "\n"; - std::cout << " Total Slots: " << m_capacity << "\n"; - std::cout << " Occupied Slots: " << m_size << " (" << m_load_factor * 100.0f << " %)\n"; - std::cout << " Removed Slots: " << m_removed_amount << " (" << m_removed_load_factor * 100.0f + std::cout << " Address: " << address_ << "\n"; + std::cout << " Total Slots: " << capacity_ << "\n"; + std::cout << " Occupied Slots: " << size_ << " (" << load_factor_ * 100.0f << " %)\n"; + std::cout << " Removed Slots: " << removed_amount_ << " (" << removed_load_factor_ * 100.0f << " %)\n"; char memory_size_str[15]; - BLI_str_format_byte_unit(memory_size_str, m_size_in_bytes, true); + BLI_str_format_byte_unit(memory_size_str, size_in_bytes_, true); std::cout << " Size: ~" << memory_size_str << "\n"; - std::cout << " Size per Slot: " << m_size_per_element << " bytes\n"; + std::cout << " Size per Slot: " << size_per_element_ << " bytes\n"; - std::cout << " Average Collisions: " << m_average_collisions << "\n"; - for (uint32_t collision_count : m_keys_by_collision_count.index_range()) { + std::cout << " Average Collisions: " << average_collisions_ << "\n"; + for (uint32_t collision_count : keys_by_collision_count_.index_range()) { std::cout << " " << collision_count - << " Collisions: " << m_keys_by_collision_count[collision_count] << "\n"; + << " Collisions: " << keys_by_collision_count_[collision_count] << "\n"; } } }; diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh index cc1bf05f936..93bbb269d30 100644 --- a/source/blender/blenlib/BLI_index_mask.hh +++ b/source/blender/blenlib/BLI_index_mask.hh @@ -46,7 +46,7 @@ namespace blender { class IndexMask { private: /* The underlying reference to sorted integers. */ - Span<uint> m_indices; + Span<uint> indices_; public: /* Creates an IndexMask that contains no indices. */ @@ -57,7 +57,7 @@ class IndexMask { * This constructor asserts that the given integers are in ascending order and that there are no * duplicates. */ - IndexMask(Span<uint> indices) : m_indices(indices) + IndexMask(Span<uint> indices) : indices_(indices) { #ifdef DEBUG for (uint i = 1; i < indices.size(); i++) { @@ -70,7 +70,7 @@ class IndexMask { * Use this method when you know that no indices are skipped. It is more efficient than preparing * an integer array all the time. */ - IndexMask(IndexRange range) : m_indices(range.as_span()) + IndexMask(IndexRange range) : indices_(range.as_span()) { } @@ -97,17 +97,17 @@ class IndexMask { operator Span<uint>() const { - return m_indices; + return indices_; } const uint *begin() const { - return m_indices.begin(); + return indices_.begin(); } const uint *end() const { - return m_indices.end(); + return indices_.end(); } /** @@ -116,7 +116,7 @@ class IndexMask { */ uint operator[](uint n) const { - return m_indices[n]; + return indices_[n]; } /** @@ -125,17 +125,17 @@ class IndexMask { */ uint min_array_size() const { - if (m_indices.size() == 0) { + if (indices_.size() == 0) { return 0; } else { - return m_indices.last() + 1; + return indices_.last() + 1; } } Span<uint> indices() const { - return m_indices; + return indices_; } /** @@ -143,7 +143,7 @@ class IndexMask { */ bool is_range() const { - return m_indices.size() > 0 && m_indices.last() - m_indices.first() == m_indices.size() - 1; + return indices_.size() > 0 && indices_.last() - indices_.first() == indices_.size() - 1; } /** @@ -153,7 +153,7 @@ class IndexMask { IndexRange as_range() const { BLI_assert(this->is_range()); - return IndexRange{m_indices.first(), m_indices.size()}; + return IndexRange{indices_.first(), indices_.size()}; } /** @@ -172,7 +172,7 @@ class IndexMask { } } else { - for (uint i : m_indices) { + for (uint i : indices_) { callback(i); } } @@ -187,7 +187,7 @@ class IndexMask { */ IndexRange index_range() const { - return m_indices.index_range(); + return indices_.index_range(); } /** @@ -195,7 +195,7 @@ class IndexMask { */ uint last() const { - return m_indices.last(); + return indices_.last(); } /** @@ -203,7 +203,7 @@ class IndexMask { */ uint size() const { - return m_indices.size(); + return indices_.size(); } }; diff --git a/source/blender/blenlib/BLI_index_range.hh b/source/blender/blenlib/BLI_index_range.hh index e2b74931537..1ae08e834ae 100644 --- a/source/blender/blenlib/BLI_index_range.hh +++ b/source/blender/blenlib/BLI_index_range.hh @@ -70,59 +70,59 @@ template<typename T> class Span; class IndexRange { private: - uint m_start = 0; - uint m_size = 0; + uint start_ = 0; + uint size_ = 0; public: IndexRange() = default; - explicit IndexRange(uint size) : m_start(0), m_size(size) + explicit IndexRange(uint size) : start_(0), size_(size) { } - IndexRange(uint start, uint size) : m_start(start), m_size(size) + IndexRange(uint start, uint size) : start_(start), size_(size) { } template<typename T> - IndexRange(const tbb::blocked_range<T> &range) : m_start(range.begin()), m_size(range.size()) + IndexRange(const tbb::blocked_range<T> &range) : start_(range.begin()), size_(range.size()) { } class Iterator { private: - uint m_current; + uint current_; public: - Iterator(uint current) : m_current(current) + Iterator(uint current) : current_(current) { } Iterator &operator++() { - m_current++; + current_++; return *this; } bool operator!=(const Iterator &iterator) const { - return m_current != iterator.m_current; + return current_ != iterator.current_; } uint operator*() const { - return m_current; + return current_; } }; Iterator begin() const { - return Iterator(m_start); + return Iterator(start_); } Iterator end() const { - return Iterator(m_start + m_size); + return Iterator(start_ + size_); } /** @@ -131,7 +131,7 @@ class IndexRange { uint operator[](uint index) const { BLI_assert(index < this->size()); - return m_start + index; + return start_ + index; } /** @@ -139,7 +139,7 @@ class IndexRange { */ friend bool operator==(IndexRange a, IndexRange b) { - return (a.m_size == b.m_size) && (a.m_start == b.m_start || a.m_size == 0); + return (a.size_ == b.size_) && (a.start_ == b.start_ || a.size_ == 0); } /** @@ -147,7 +147,7 @@ class IndexRange { */ uint size() const { - return m_size; + return size_; } /** @@ -155,7 +155,7 @@ class IndexRange { */ IndexRange after(uint n) const { - return IndexRange(m_start + m_size, n); + return IndexRange(start_ + size_, n); } /** @@ -163,7 +163,7 @@ class IndexRange { */ IndexRange before(uint n) const { - return IndexRange(m_start - n, n); + return IndexRange(start_ - n, n); } /** @@ -173,7 +173,7 @@ class IndexRange { uint first() const { BLI_assert(this->size() > 0); - return m_start; + return start_; } /** @@ -183,7 +183,7 @@ class IndexRange { uint last() const { BLI_assert(this->size() > 0); - return m_start + m_size - 1; + return start_ + size_ - 1; } /** @@ -191,7 +191,7 @@ class IndexRange { */ uint one_after_last() const { - return m_start + m_size; + return start_ + size_; } /** @@ -199,7 +199,7 @@ class IndexRange { */ uint start() const { - return m_start; + return start_; } /** @@ -207,7 +207,7 @@ class IndexRange { */ bool contains(uint value) const { - return value >= m_start && value < m_start + m_size; + return value >= start_ && value < start_ + size_; } /** @@ -215,8 +215,8 @@ class IndexRange { */ IndexRange slice(uint start, uint size) const { - uint new_start = m_start + start; - BLI_assert(new_start + size <= m_start + m_size || size == 0); + uint new_start = start_ + start; + BLI_assert(new_start + size <= start_ + size_ || size == 0); return IndexRange(new_start, size); } IndexRange slice(IndexRange range) const diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh index 2a0dc939cb9..03264fef3bd 100644 --- a/source/blender/blenlib/BLI_linear_allocator.hh +++ b/source/blender/blenlib/BLI_linear_allocator.hh @@ -33,30 +33,30 @@ namespace blender { template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopyable, NonMovable { private: - Allocator m_allocator; - Vector<void *> m_owned_buffers; - Vector<Span<char>> m_unused_borrowed_buffers; + Allocator allocator_; + Vector<void *> owned_buffers_; + Vector<Span<char>> unused_borrowed_buffers_; - uintptr_t m_current_begin; - uintptr_t m_current_end; - uint m_next_min_alloc_size; + uintptr_t current_begin_; + uintptr_t current_end_; + uint next_min_alloc_size_; #ifdef DEBUG - uint m_debug_allocated_amount = 0; + uint debug_allocated_amount_ = 0; #endif public: LinearAllocator() { - m_current_begin = 0; - m_current_end = 0; - m_next_min_alloc_size = 64; + current_begin_ = 0; + current_end_ = 0; + next_min_alloc_size_ = 64; } ~LinearAllocator() { - for (void *ptr : m_owned_buffers) { - m_allocator.deallocate(ptr); + for (void *ptr : owned_buffers_) { + allocator_.deallocate(ptr); } } @@ -72,15 +72,15 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya BLI_assert(is_power_of_2_i(alignment)); #ifdef DEBUG - m_debug_allocated_amount += size; + debug_allocated_amount_ += size; #endif uintptr_t alignment_mask = alignment - 1; - uintptr_t potential_allocation_begin = (m_current_begin + alignment_mask) & ~alignment_mask; + uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) & ~alignment_mask; uintptr_t potential_allocation_end = potential_allocation_begin + size; - if (potential_allocation_end <= m_current_end) { - m_current_begin = potential_allocation_end; + if (potential_allocation_end <= current_end_) { + current_begin_ = potential_allocation_end; return (void *)potential_allocation_begin; } else { @@ -183,7 +183,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya */ void provide_buffer(void *buffer, uint size) { - m_unused_borrowed_buffers.append(Span<char>((char *)buffer, size)); + unused_borrowed_buffers_.append(Span<char>((char *)buffer, size)); } template<size_t Size, size_t Alignment> @@ -195,23 +195,23 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya private: void allocate_new_buffer(uint min_allocation_size) { - for (uint i : m_unused_borrowed_buffers.index_range()) { - Span<char> buffer = m_unused_borrowed_buffers[i]; + for (uint i : unused_borrowed_buffers_.index_range()) { + Span<char> buffer = unused_borrowed_buffers_[i]; if (buffer.size() >= min_allocation_size) { - m_unused_borrowed_buffers.remove_and_reorder(i); - m_current_begin = (uintptr_t)buffer.begin(); - m_current_end = (uintptr_t)buffer.end(); + unused_borrowed_buffers_.remove_and_reorder(i); + current_begin_ = (uintptr_t)buffer.begin(); + current_end_ = (uintptr_t)buffer.end(); return; } } - uint size_in_bytes = power_of_2_min_u(std::max(min_allocation_size, m_next_min_alloc_size)); - m_next_min_alloc_size = size_in_bytes * 2; + uint size_in_bytes = power_of_2_min_u(std::max(min_allocation_size, next_min_alloc_size_)); + next_min_alloc_size_ = size_in_bytes * 2; - void *buffer = m_allocator.allocate(size_in_bytes, 8, AT); - m_owned_buffers.append(buffer); - m_current_begin = (uintptr_t)buffer; - m_current_end = m_current_begin + size_in_bytes; + void *buffer = allocator_.allocate(size_in_bytes, 8, AT); + owned_buffers_.append(buffer); + current_begin_ = (uintptr_t)buffer; + current_end_ = current_begin_ + size_in_bytes; } }; diff --git a/source/blender/blenlib/BLI_listbase_wrapper.hh b/source/blender/blenlib/BLI_listbase_wrapper.hh index 9cf7fc5c0e0..047099eb36e 100644 --- a/source/blender/blenlib/BLI_listbase_wrapper.hh +++ b/source/blender/blenlib/BLI_listbase_wrapper.hh @@ -33,10 +33,10 @@ namespace blender { template<typename T> class ListBaseWrapper { private: - ListBase *m_listbase; + ListBase *listbase_; public: - ListBaseWrapper(ListBase *listbase) : m_listbase(listbase) + ListBaseWrapper(ListBase *listbase) : listbase_(listbase) { BLI_assert(listbase); } @@ -47,17 +47,17 @@ template<typename T> class ListBaseWrapper { class Iterator { private: - ListBase *m_listbase; - T *m_current; + ListBase *listbase_; + T *current_; public: - Iterator(ListBase *listbase, T *current) : m_listbase(listbase), m_current(current) + Iterator(ListBase *listbase, T *current) : listbase_(listbase), current_(current) { } Iterator &operator++() { - m_current = m_current->next; + current_ = current_->next; return *this; } @@ -70,28 +70,28 @@ template<typename T> class ListBaseWrapper { bool operator!=(const Iterator &iterator) const { - return m_current != iterator.m_current; + return current_ != iterator.current_; } T *operator*() const { - return m_current; + return current_; } }; Iterator begin() const { - return Iterator(m_listbase, (T *)m_listbase->first); + return Iterator(listbase_, (T *)listbase_->first); } Iterator end() const { - return Iterator(m_listbase, nullptr); + return Iterator(listbase_, nullptr); } T get(uint index) const { - void *ptr = BLI_findlink(m_listbase, index); + void *ptr = BLI_findlink(listbase_, index); BLI_assert(ptr); return (T *)ptr; } diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh index 688f334001f..0a044afe8af 100644 --- a/source/blender/blenlib/BLI_map.hh +++ b/source/blender/blenlib/BLI_map.hh @@ -129,30 +129,30 @@ class Map { * Slots are either empty, occupied or removed. The number of occupied slots can be computed by * subtracting the removed slots from the occupied-and-removed slots. */ - uint32_t m_removed_slots; - uint32_t m_occupied_and_removed_slots; + uint32_t removed_slots_; + uint32_t occupied_and_removed_slots_; /** * The maximum number of slots that can be used (either occupied or removed) until the set has to * grow. This is the total number of slots times the max load factor. */ - uint32_t m_usable_slots; + uint32_t usable_slots_; /** * The number of slots minus one. This is a bit mask that can be used to turn any integer into a * valid slot index efficiently. */ - uint32_t m_slot_mask; + uint32_t slot_mask_; /** This is called to hash incoming keys. */ - Hash m_hash; + Hash hash_; /** This is called to check equality of two keys. */ - IsEqual m_is_equal; + IsEqual is_equal_; /** The max load factor is 1/2 = 50% by default. */ #define LOAD_FACTOR 1, 2 - LoadFactor m_max_load_factor = LoadFactor(LOAD_FACTOR); + LoadFactor max_load_factor_ = LoadFactor(LOAD_FACTOR); using SlotArray = Array<Slot, LoadFactor::compute_total_slots(InlineBufferCapacity, LOAD_FACTOR), Allocator>; #undef LOAD_FACTOR @@ -161,12 +161,12 @@ class Map { * This is the array that contains the actual slots. There is always at least one empty slot and * the size of the array is a power of two. */ - SlotArray m_slots; + SlotArray slots_; /** Iterate over a slot index sequence for a given hash. */ #define MAP_SLOT_PROBING_BEGIN(HASH, R_SLOT) \ - SLOT_PROBING_BEGIN (ProbingStrategy, HASH, m_slot_mask, SLOT_INDEX) \ - auto &R_SLOT = m_slots[SLOT_INDEX]; + SLOT_PROBING_BEGIN (ProbingStrategy, HASH, slot_mask_, SLOT_INDEX) \ + auto &R_SLOT = slots_[SLOT_INDEX]; #define MAP_SLOT_PROBING_END() SLOT_PROBING_END() public: @@ -176,13 +176,13 @@ class Map { * operation is performed on the first insertion. */ Map() - : m_removed_slots(0), - m_occupied_and_removed_slots(0), - m_usable_slots(0), - m_slot_mask(0), - m_hash(), - m_is_equal(), - m_slots(1) + : removed_slots_(0), + occupied_and_removed_slots_(0), + usable_slots_(0), + slot_mask_(0), + hash_(), + is_equal_(), + slots_(1) { } @@ -191,13 +191,13 @@ class Map { Map(const Map &other) = default; Map(Map &&other) noexcept - : m_removed_slots(other.m_removed_slots), - m_occupied_and_removed_slots(other.m_occupied_and_removed_slots), - m_usable_slots(other.m_usable_slots), - m_slot_mask(other.m_slot_mask), - m_hash(std::move(other.m_hash)), - m_is_equal(std::move(other.m_is_equal)), - m_slots(std::move(other.m_slots)) + : removed_slots_(other.removed_slots_), + occupied_and_removed_slots_(other.occupied_and_removed_slots_), + usable_slots_(other.usable_slots_), + slot_mask_(other.slot_mask_), + hash_(std::move(other.hash_)), + is_equal_(std::move(other.is_equal_)), + slots_(std::move(other.slots_)) { other.~Map(); new (&other) Map(); @@ -233,19 +233,19 @@ class Map { */ void add_new(const Key &key, const Value &value) { - this->add_new__impl(key, value, m_hash(key)); + this->add_new__impl(key, value, hash_(key)); } void add_new(const Key &key, Value &&value) { - this->add_new__impl(key, std::move(value), m_hash(key)); + this->add_new__impl(key, std::move(value), hash_(key)); } void add_new(Key &&key, const Value &value) { - this->add_new__impl(std::move(key), value, m_hash(key)); + this->add_new__impl(std::move(key), value, hash_(key)); } void add_new(Key &&key, Value &&value) { - this->add_new__impl(std::move(key), std::move(value), m_hash(key)); + this->add_new__impl(std::move(key), std::move(value), hash_(key)); } /** @@ -279,7 +279,7 @@ class Map { bool add_as(ForwardKey &&key, ForwardValue &&value) { return this->add__impl( - std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), m_hash(key)); + std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), hash_(key)); } /** @@ -313,7 +313,7 @@ class Map { bool add_overwrite_as(ForwardKey &&key, ForwardValue &&value) { return this->add_overwrite__impl( - std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), m_hash(key)); + std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), hash_(key)); } /** @@ -331,7 +331,7 @@ class Map { */ template<typename ForwardKey> bool contains_as(const ForwardKey &key) const { - return this->contains__impl(key, m_hash(key)); + return this->contains__impl(key, hash_(key)); } /** @@ -350,7 +350,7 @@ class Map { */ template<typename ForwardKey> bool remove_as(const ForwardKey &key) { - return this->remove__impl(key, m_hash(key)); + return this->remove__impl(key, hash_(key)); } /** @@ -368,7 +368,7 @@ class Map { */ template<typename ForwardKey> void remove_contained_as(const ForwardKey &key) { - this->remove_contained__impl(key, m_hash(key)); + this->remove_contained__impl(key, hash_(key)); } /** @@ -385,7 +385,7 @@ class Map { */ template<typename ForwardKey> Value pop_as(const ForwardKey &key) { - return this->pop__impl(key, m_hash(key)); + return this->pop__impl(key, hash_(key)); } /** @@ -402,7 +402,7 @@ class Map { */ template<typename ForwardKey> std::optional<Value> pop_try_as(const ForwardKey &key) { - return this->pop_try__impl(key, m_hash(key)); + return this->pop_try__impl(key, hash_(key)); } /** @@ -424,7 +424,7 @@ class Map { template<typename ForwardKey, typename ForwardValue> Value pop_default_as(const ForwardKey &key, ForwardValue &&default_value) { - return this->pop_default__impl(key, std::forward<ForwardValue>(default_value), m_hash(key)); + return this->pop_default__impl(key, std::forward<ForwardValue>(default_value), hash_(key)); } /** @@ -470,7 +470,7 @@ class Map { const ModifyValueF &modify_value) -> decltype(create_value(nullptr)) { return this->add_or_modify__impl( - std::forward<ForwardKey>(key), create_value, modify_value, m_hash(key)); + std::forward<ForwardKey>(key), create_value, modify_value, hash_(key)); } /** @@ -493,11 +493,11 @@ class Map { */ template<typename ForwardKey> const Value *lookup_ptr_as(const ForwardKey &key) const { - return this->lookup_ptr__impl(key, m_hash(key)); + return this->lookup_ptr__impl(key, hash_(key)); } template<typename ForwardKey> Value *lookup_ptr_as(const ForwardKey &key) { - return const_cast<Value *>(this->lookup_ptr__impl(key, m_hash(key))); + return const_cast<Value *>(this->lookup_ptr__impl(key, hash_(key))); } /** @@ -582,7 +582,7 @@ class Map { Value &lookup_or_add_as(ForwardKey &&key, ForwardValue &&value) { return this->lookup_or_add__impl( - std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), m_hash(key)); + std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), hash_(key)); } /** @@ -610,7 +610,7 @@ class Map { template<typename ForwardKey, typename CreateValueF> Value &lookup_or_add_cb_as(ForwardKey &&key, const CreateValueF &create_value) { - return this->lookup_or_add_cb__impl(std::forward<ForwardKey>(key), create_value, m_hash(key)); + return this->lookup_or_add_cb__impl(std::forward<ForwardKey>(key), create_value, hash_(key)); } /** @@ -641,9 +641,9 @@ class Map { */ template<typename FuncT> void foreach_item(const FuncT &func) const { - uint32_t size = m_slots.size(); + uint32_t size = slots_.size(); for (uint32_t i = 0; i < size; i++) { - const Slot &slot = m_slots[i]; + const Slot &slot = slots_[i]; if (slot.is_occupied()) { const Key &key = *slot.key(); const Value &value = *slot.value(); @@ -657,21 +657,19 @@ class Map { * This uses the "curiously recurring template pattern" (CRTP). */ template<typename SubIterator> struct BaseIterator { - Slot *m_slots; - uint32_t m_total_slots; - uint32_t m_current_slot; + Slot *slots_; + uint32_t total_slots_; + uint32_t current_slot_; BaseIterator(const Slot *slots, uint32_t total_slots, uint32_t current_slot) - : m_slots(const_cast<Slot *>(slots)), - m_total_slots(total_slots), - m_current_slot(current_slot) + : slots_(const_cast<Slot *>(slots)), total_slots_(total_slots), current_slot_(current_slot) { } BaseIterator &operator++() { - while (++m_current_slot < m_total_slots) { - if (m_slots[m_current_slot].is_occupied()) { + while (++current_slot_ < total_slots_) { + if (slots_[current_slot_].is_occupied()) { break; } } @@ -680,16 +678,16 @@ class Map { friend bool operator!=(const BaseIterator &a, const BaseIterator &b) { - BLI_assert(a.m_slots == b.m_slots); - BLI_assert(a.m_total_slots == b.m_total_slots); - return a.m_current_slot != b.m_current_slot; + BLI_assert(a.slots_ == b.slots_); + BLI_assert(a.total_slots_ == b.total_slots_); + return a.current_slot_ != b.current_slot_; } SubIterator begin() const { - for (uint32_t i = 0; i < m_total_slots; i++) { - if (m_slots[i].is_occupied()) { - return SubIterator(m_slots, m_total_slots, i); + for (uint32_t i = 0; i < total_slots_; i++) { + if (slots_[i].is_occupied()) { + return SubIterator(slots_, total_slots_, i); } } return this->end(); @@ -697,12 +695,12 @@ class Map { SubIterator end() const { - return SubIterator(m_slots, m_total_slots, m_total_slots); + return SubIterator(slots_, total_slots_, total_slots_); } Slot ¤t_slot() const { - return m_slots[m_current_slot]; + return slots_[current_slot_]; } }; @@ -794,7 +792,7 @@ class Map { */ KeyIterator keys() const { - return KeyIterator(m_slots.data(), m_slots.size(), 0); + return KeyIterator(slots_.data(), slots_.size(), 0); } /** @@ -803,7 +801,7 @@ class Map { */ ValueIterator values() const { - return ValueIterator(m_slots.data(), m_slots.size(), 0); + return ValueIterator(slots_.data(), slots_.size(), 0); } /** @@ -812,7 +810,7 @@ class Map { */ MutableValueIterator values() { - return MutableValueIterator(m_slots.data(), m_slots.size(), 0); + return MutableValueIterator(slots_.data(), slots_.size(), 0); } /** @@ -822,7 +820,7 @@ class Map { */ ItemIterator items() const { - return ItemIterator(m_slots.data(), m_slots.size(), 0); + return ItemIterator(slots_.data(), slots_.size(), 0); } /** @@ -834,7 +832,7 @@ class Map { */ MutableItemIterator items() { - return MutableItemIterator(m_slots.data(), m_slots.size(), 0); + return MutableItemIterator(slots_.data(), slots_.size(), 0); } /** @@ -851,7 +849,7 @@ class Map { */ uint32_t size() const { - return m_occupied_and_removed_slots - m_removed_slots; + return occupied_and_removed_slots_ - removed_slots_; } /** @@ -861,7 +859,7 @@ class Map { */ bool is_empty() const { - return m_occupied_and_removed_slots == m_removed_slots; + return occupied_and_removed_slots_ == removed_slots_; } /** @@ -869,7 +867,7 @@ class Map { */ uint32_t capacity() const { - return m_slots.size(); + return slots_.size(); } /** @@ -877,7 +875,7 @@ class Map { */ uint32_t removed_amount() const { - return m_removed_slots; + return removed_slots_; } /** @@ -894,7 +892,7 @@ class Map { */ uint32_t size_in_bytes() const { - return (uint32_t)(sizeof(Slot) * m_slots.size()); + return (uint32_t)(sizeof(Slot) * slots_.size()); } /** @@ -903,7 +901,7 @@ class Map { */ void reserve(uint32_t n) { - if (m_usable_slots < n) { + if (usable_slots_ < n) { this->realloc_and_reinsert(n); } } @@ -923,14 +921,14 @@ class Map { */ uint32_t count_collisions(const Key &key) const { - return this->count_collisions__impl(key, m_hash(key)); + return this->count_collisions__impl(key, hash_(key)); } private: BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots) { uint32_t total_slots, usable_slots; - m_max_load_factor.compute_total_and_usable_slots( + max_load_factor_.compute_total_and_usable_slots( SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots); uint32_t new_slot_mask = total_slots - 1; @@ -938,18 +936,18 @@ class Map { * Optimize the case when the map was empty beforehand. We can avoid some copies here. */ if (this->size() == 0) { - m_slots.~Array(); - new (&m_slots) SlotArray(total_slots); - m_removed_slots = 0; - m_occupied_and_removed_slots = 0; - m_usable_slots = usable_slots; - m_slot_mask = new_slot_mask; + slots_.~Array(); + new (&slots_) SlotArray(total_slots); + removed_slots_ = 0; + occupied_and_removed_slots_ = 0; + usable_slots_ = usable_slots; + slot_mask_ = new_slot_mask; return; } SlotArray new_slots(total_slots); - for (Slot &slot : m_slots) { + for (Slot &slot : slots_) { if (slot.is_occupied()) { this->add_after_grow_and_destruct_old(slot, new_slots, new_slot_mask); } @@ -957,12 +955,12 @@ class Map { /* All occupied slots have been destructed already and empty/removed slots are assumed to be * trivially destructible. */ - m_slots.clear_without_destruct(); - m_slots = std::move(new_slots); - m_occupied_and_removed_slots -= m_removed_slots; - m_usable_slots = usable_slots; - m_removed_slots = 0; - m_slot_mask = new_slot_mask; + slots_.clear_without_destruct(); + slots_ = std::move(new_slots); + occupied_and_removed_slots_ -= removed_slots_; + usable_slots_ = usable_slots; + removed_slots_ = 0; + slot_mask_ = new_slot_mask; } void add_after_grow_and_destruct_old(Slot &old_slot, @@ -986,7 +984,7 @@ class Map { if (slot.is_empty()) { return false; } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return true; } } @@ -999,7 +997,7 @@ class Map { BLI_assert(!this->contains_as(key)); this->ensure_can_add(); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; MAP_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { @@ -1018,10 +1016,10 @@ class Map { MAP_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { slot.occupy(std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return true; } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return false; } } @@ -1031,9 +1029,9 @@ class Map { template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash) { MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { slot.remove(); - m_removed_slots++; + removed_slots_++; return true; } if (slot.is_empty()) { @@ -1047,10 +1045,10 @@ class Map { { BLI_assert(this->contains_as(key)); - m_removed_slots++; + removed_slots_++; MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { slot.remove(); return; } @@ -1062,10 +1060,10 @@ class Map { { BLI_assert(this->contains_as(key)); - m_removed_slots++; + removed_slots_++; MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { Value value = std::move(*slot.value()); slot.remove(); return value; @@ -1078,10 +1076,10 @@ class Map { std::optional<Value> pop_try__impl(const ForwardKey &key, uint32_t hash) { MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { std::optional<Value> value = std::move(*slot.value()); slot.remove(); - m_removed_slots++; + removed_slots_++; return value; } if (slot.is_empty()) { @@ -1095,10 +1093,10 @@ class Map { Value pop_default__impl(const ForwardKey &key, ForwardValue &&default_value, uint32_t hash) { MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { Value value = std::move(*slot.value()); slot.remove(); - m_removed_slots++; + removed_slots_++; return value; } if (slot.is_empty()) { @@ -1123,12 +1121,12 @@ class Map { MAP_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; slot.occupy_without_value(std::forward<ForwardKey>(key), hash); Value *value_ptr = slot.value(); return create_value(value_ptr); } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { Value *value_ptr = slot.value(); return modify_value(value_ptr); } @@ -1144,10 +1142,10 @@ class Map { MAP_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { slot.occupy(std::forward<ForwardKey>(key), create_value(), hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return *slot.value(); } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return *slot.value(); } } @@ -1162,10 +1160,10 @@ class Map { MAP_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { slot.occupy(std::forward<ForwardKey>(key), std::forward<ForwardValue>(value), hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return *slot.value(); } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return *slot.value(); } } @@ -1194,7 +1192,7 @@ class Map { if (slot.is_empty()) { return nullptr; } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return slot.value(); } } @@ -1207,7 +1205,7 @@ class Map { uint32_t collisions = 0; MAP_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return collisions; } if (slot.is_empty()) { @@ -1220,9 +1218,9 @@ class Map { void ensure_can_add() { - if (m_occupied_and_removed_slots >= m_usable_slots) { + if (occupied_and_removed_slots_ >= usable_slots_) { this->realloc_and_reinsert(this->size() + 1); - BLI_assert(m_occupied_and_removed_slots < m_usable_slots); + BLI_assert(occupied_and_removed_slots_ < usable_slots_); } } }; @@ -1234,59 +1232,59 @@ class Map { template<typename Key, typename Value> class StdUnorderedMapWrapper { private: using MapType = std::unordered_map<Key, Value, blender::DefaultHash<Key>>; - MapType m_map; + MapType map_; public: uint32_t size() const { - return (uint32_t)m_map.size(); + return (uint32_t)map_.size(); } bool is_empty() const { - return m_map.empty(); + return map_.empty(); } void reserve(uint32_t n) { - m_map.reserve(n); + map_.reserve(n); } template<typename ForwardKey, typename ForwardValue> void add_new(ForwardKey &&key, ForwardValue &&value) { - m_map.insert({std::forward<ForwardKey>(key), std::forward<ForwardValue>(value)}); + map_.insert({std::forward<ForwardKey>(key), std::forward<ForwardValue>(value)}); } template<typename ForwardKey, typename ForwardValue> bool add(ForwardKey &&key, ForwardValue &&value) { - return m_map.insert({std::forward<ForwardKey>(key), std::forward<ForwardValue>(value)}).second; + return map_.insert({std::forward<ForwardKey>(key), std::forward<ForwardValue>(value)}).second; } bool contains(const Key &key) const { - return m_map.find(key) != m_map.end(); + return map_.find(key) != map_.end(); } bool remove(const Key &key) { - return (bool)m_map.erase(key); + return (bool)map_.erase(key); } Value &lookup(const Key &key) { - return m_map.find(key)->second; + return map_.find(key)->second; } const Value &lookup(const Key &key) const { - return m_map.find(key)->second; + return map_.find(key)->second; } void clear() { - m_map.clear(); + map_.clear(); } void print_stats(StringRef UNUSED(name) = "") const diff --git a/source/blender/blenlib/BLI_map_slots.hh b/source/blender/blenlib/BLI_map_slots.hh index f12eefcaf0b..c3d88205e0a 100644 --- a/source/blender/blenlib/BLI_map_slots.hh +++ b/source/blender/blenlib/BLI_map_slots.hh @@ -52,9 +52,9 @@ template<typename Key, typename Value> class SimpleMapSlot { Removed = 2, }; - State m_state; - AlignedBuffer<sizeof(Key), alignof(Key)> m_key_buffer; - AlignedBuffer<sizeof(Value), alignof(Value)> m_value_buffer; + State state_; + AlignedBuffer<sizeof(Key), alignof(Key)> key_buffer_; + AlignedBuffer<sizeof(Value), alignof(Value)> value_buffer_; public: /** @@ -62,7 +62,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ SimpleMapSlot() { - m_state = Empty; + state_ = Empty; } /** @@ -70,7 +70,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ ~SimpleMapSlot() { - if (m_state == Occupied) { + if (state_ == Occupied) { this->key()->~Key(); this->value()->~Value(); } @@ -82,8 +82,8 @@ template<typename Key, typename Value> class SimpleMapSlot { */ SimpleMapSlot(const SimpleMapSlot &other) { - m_state = other.m_state; - if (other.m_state == Occupied) { + state_ = other.state_; + if (other.state_ == Occupied) { new ((void *)this->key()) Key(*other.key()); new ((void *)this->value()) Value(*other.value()); } @@ -96,8 +96,8 @@ template<typename Key, typename Value> class SimpleMapSlot { */ SimpleMapSlot(SimpleMapSlot &&other) noexcept { - m_state = other.m_state; - if (other.m_state == Occupied) { + state_ = other.state_; + if (other.state_ == Occupied) { new ((void *)this->key()) Key(std::move(*other.key())); new ((void *)this->value()) Value(std::move(*other.value())); } @@ -108,7 +108,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ Key *key() { - return (Key *)m_key_buffer.ptr(); + return (Key *)key_buffer_.ptr(); } /** @@ -116,7 +116,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ const Key *key() const { - return (const Key *)m_key_buffer.ptr(); + return (const Key *)key_buffer_.ptr(); } /** @@ -124,7 +124,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ Value *value() { - return (Value *)m_value_buffer.ptr(); + return (Value *)value_buffer_.ptr(); } /** @@ -132,7 +132,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ const Value *value() const { - return (const Value *)m_value_buffer.ptr(); + return (const Value *)value_buffer_.ptr(); } /** @@ -140,7 +140,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ bool is_occupied() const { - return m_state == Occupied; + return state_ == Occupied; } /** @@ -148,7 +148,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ bool is_empty() const { - return m_state == Empty; + return state_ == Empty; } /** @@ -169,7 +169,7 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_state = Occupied; + state_ = Occupied; new ((void *)this->key()) Key(std::move(*other.key())); new ((void *)this->value()) Value(std::move(*other.value())); other.key()->~Key(); @@ -183,7 +183,7 @@ template<typename Key, typename Value> class SimpleMapSlot { template<typename ForwardKey, typename IsEqual> bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const { - if (m_state == Occupied) { + if (state_ == Occupied) { return is_equal(key, *this->key()); } return false; @@ -208,7 +208,7 @@ template<typename Key, typename Value> class SimpleMapSlot { template<typename ForwardKey> void occupy_without_value(ForwardKey &&key, uint32_t UNUSED(hash)) { BLI_assert(!this->is_occupied()); - m_state = Occupied; + state_ = Occupied; new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } @@ -219,7 +219,7 @@ template<typename Key, typename Value> class SimpleMapSlot { void remove() { BLI_assert(this->is_occupied()); - m_state = Removed; + state_ = Removed; this->key()->~Key(); this->value()->~Value(); } @@ -235,61 +235,61 @@ template<typename Key, typename Value> class SimpleMapSlot { */ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot { private: - Key m_key = KeyInfo::get_empty(); - AlignedBuffer<sizeof(Value), alignof(Value)> m_value_buffer; + Key key_ = KeyInfo::get_empty(); + AlignedBuffer<sizeof(Value), alignof(Value)> value_buffer_; public: IntrusiveMapSlot() = default; ~IntrusiveMapSlot() { - if (KeyInfo::is_not_empty_or_removed(m_key)) { + if (KeyInfo::is_not_empty_or_removed(key_)) { this->value()->~Value(); } } - IntrusiveMapSlot(const IntrusiveMapSlot &other) : m_key(other.m_key) + IntrusiveMapSlot(const IntrusiveMapSlot &other) : key_(other.key_) { - if (KeyInfo::is_not_empty_or_removed(m_key)) { + if (KeyInfo::is_not_empty_or_removed(key_)) { new ((void *)this->value()) Value(*other.value()); } } - IntrusiveMapSlot(IntrusiveMapSlot &&other) noexcept : m_key(other.m_key) + IntrusiveMapSlot(IntrusiveMapSlot &&other) noexcept : key_(other.key_) { - if (KeyInfo::is_not_empty_or_removed(m_key)) { + if (KeyInfo::is_not_empty_or_removed(key_)) { new ((void *)this->value()) Value(std::move(*other.value())); } } Key *key() { - return &m_key; + return &key_; } const Key *key() const { - return &m_key; + return &key_; } Value *value() { - return (Value *)m_value_buffer.ptr(); + return (Value *)value_buffer_.ptr(); } const Value *value() const { - return (const Value *)m_value_buffer.ptr(); + return (const Value *)value_buffer_.ptr(); } bool is_occupied() const { - return KeyInfo::is_not_empty_or_removed(m_key); + return KeyInfo::is_not_empty_or_removed(key_); } bool is_empty() const { - return KeyInfo::is_empty(m_key); + return KeyInfo::is_empty(key_); } template<typename Hash> uint32_t get_hash(const Hash &hash) @@ -302,9 +302,9 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_key = std::move(other.m_key); + key_ = std::move(other.key_); new ((void *)this->value()) Value(std::move(*other.value())); - other.m_key.~Key(); + other.key_.~Key(); other.value()->~Value(); } @@ -312,7 +312,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const { BLI_assert(KeyInfo::is_not_empty_or_removed(key)); - return is_equal(key, m_key); + return is_equal(key, key_); } template<typename ForwardKey, typename ForwardValue> @@ -328,13 +328,13 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot { BLI_assert(!this->is_occupied()); BLI_assert(KeyInfo::is_not_empty_or_removed(key)); - m_key = std::forward<ForwardKey>(key); + key_ = std::forward<ForwardKey>(key); } void remove() { BLI_assert(this->is_occupied()); - KeyInfo::remove(m_key); + KeyInfo::remove(key_); this->value()->~Value(); } }; diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 0c2cae6c606..44d25340778 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -228,17 +228,17 @@ template<typename T> using destruct_ptr = std::unique_ptr<T, DestructValueAtAddr template<size_t Size, size_t Alignment> class alignas(Alignment) AlignedBuffer { private: /* Don't create an empty array. This causes problems with some compilers. */ - char m_buffer[(Size > 0) ? Size : 1]; + char buffer_[(Size > 0) ? Size : 1]; public: void *ptr() { - return (void *)m_buffer; + return (void *)buffer_; } const void *ptr() const { - return (const void *)m_buffer; + return (const void *)buffer_; } }; diff --git a/source/blender/blenlib/BLI_probing_strategies.hh b/source/blender/blenlib/BLI_probing_strategies.hh index 29ebe28aff9..3296ce9a968 100644 --- a/source/blender/blenlib/BLI_probing_strategies.hh +++ b/source/blender/blenlib/BLI_probing_strategies.hh @@ -65,21 +65,21 @@ namespace blender { */ class LinearProbingStrategy { private: - uint32_t m_hash; + uint32_t hash_; public: - LinearProbingStrategy(uint32_t hash) : m_hash(hash) + LinearProbingStrategy(uint32_t hash) : hash_(hash) { } void next() { - m_hash++; + hash_++; } uint32_t get() const { - return m_hash; + return hash_; } uint32_t linear_steps() const @@ -101,25 +101,25 @@ class LinearProbingStrategy { */ class QuadraticProbingStrategy { private: - uint32_t m_original_hash; - uint32_t m_current_hash; - uint32_t m_iteration; + uint32_t original_hash_; + uint32_t current_hash_; + uint32_t iteration_; public: QuadraticProbingStrategy(uint32_t hash) - : m_original_hash(hash), m_current_hash(hash), m_iteration(1) + : original_hash_(hash), current_hash_(hash), iteration_(1) { } void next() { - m_current_hash = m_original_hash + ((m_iteration * m_iteration + m_iteration) >> 1); - m_iteration++; + current_hash_ = original_hash_ + ((iteration_ * iteration_ + iteration_) >> 1); + iteration_++; } uint32_t get() const { - return m_current_hash; + return current_hash_; } uint32_t linear_steps() const @@ -140,11 +140,11 @@ class QuadraticProbingStrategy { */ template<uint32_t LinearSteps = 1, bool PreShuffle = false> class PythonProbingStrategy { private: - uint32_t m_hash; - uint32_t m_perturb; + uint32_t hash_; + uint32_t perturb_; public: - PythonProbingStrategy(uint32_t hash) : m_hash(hash), m_perturb(hash) + PythonProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash) { if (PreShuffle) { this->next(); @@ -153,13 +153,13 @@ template<uint32_t LinearSteps = 1, bool PreShuffle = false> class PythonProbingS void next() { - m_perturb >>= 5; - m_hash = 5 * m_hash + 1 + m_perturb; + perturb_ >>= 5; + hash_ = 5 * hash_ + 1 + perturb_; } uint32_t get() const { - return m_hash; + return hash_; } uint32_t linear_steps() const @@ -175,11 +175,11 @@ template<uint32_t LinearSteps = 1, bool PreShuffle = false> class PythonProbingS */ template<uint32_t LinearSteps = 2, bool PreShuffle = false> class ShuffleProbingStrategy { private: - uint32_t m_hash; - uint32_t m_perturb; + uint32_t hash_; + uint32_t perturb_; public: - ShuffleProbingStrategy(uint32_t hash) : m_hash(hash), m_perturb(hash) + ShuffleProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash) { if (PreShuffle) { this->next(); @@ -188,18 +188,18 @@ template<uint32_t LinearSteps = 2, bool PreShuffle = false> class ShuffleProbing void next() { - if (m_perturb != 0) { - m_perturb >>= 10; - m_hash = ((m_hash >> 16) ^ m_hash) * 0x45d9f3b + m_perturb; + if (perturb_ != 0) { + perturb_ >>= 10; + hash_ = ((hash_ >> 16) ^ hash_) * 0x45d9f3b + perturb_; } else { - m_hash = 5 * m_hash + 1; + hash_ = 5 * hash_ + 1; } } uint32_t get() const { - return m_hash; + return hash_; } uint32_t linear_steps() const diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh index c3dec147ac6..86fea8f39e7 100644 --- a/source/blender/blenlib/BLI_set.hh +++ b/source/blender/blenlib/BLI_set.hh @@ -128,30 +128,30 @@ class Set { * Slots are either empty, occupied or removed. The number of occupied slots can be computed by * subtracting the removed slots from the occupied-and-removed slots. */ - uint32_t m_removed_slots; - uint32_t m_occupied_and_removed_slots; + uint32_t removed_slots_; + uint32_t occupied_and_removed_slots_; /** * The maximum number of slots that can be used (either occupied or removed) until the set has to * grow. This is the total number of slots times the max load factor. */ - uint32_t m_usable_slots; + uint32_t usable_slots_; /** * The number of slots minus one. This is a bit mask that can be used to turn any integer into a * valid slot index efficiently. */ - uint32_t m_slot_mask; + uint32_t slot_mask_; /** This is called to hash incoming keys. */ - Hash m_hash; + Hash hash_; /** This is called to check equality of two keys. */ - IsEqual m_is_equal; + IsEqual is_equal_; /** The max load factor is 1/2 = 50% by default. */ #define LOAD_FACTOR 1, 2 - LoadFactor m_max_load_factor = LoadFactor(LOAD_FACTOR); + LoadFactor max_load_factor_ = LoadFactor(LOAD_FACTOR); using SlotArray = Array<Slot, LoadFactor::compute_total_slots(InlineBufferCapacity, LOAD_FACTOR), Allocator>; #undef LOAD_FACTOR @@ -160,12 +160,12 @@ class Set { * This is the array that contains the actual slots. There is always at least one empty slot and * the size of the array is a power of two. */ - SlotArray m_slots; + SlotArray slots_; /** Iterate over a slot index sequence for a given hash. */ #define SET_SLOT_PROBING_BEGIN(HASH, R_SLOT) \ - SLOT_PROBING_BEGIN (ProbingStrategy, HASH, m_slot_mask, SLOT_INDEX) \ - auto &R_SLOT = m_slots[SLOT_INDEX]; + SLOT_PROBING_BEGIN (ProbingStrategy, HASH, slot_mask_, SLOT_INDEX) \ + auto &R_SLOT = slots_[SLOT_INDEX]; #define SET_SLOT_PROBING_END() SLOT_PROBING_END() public: @@ -175,11 +175,11 @@ class Set { * grow operation is performed on the first insertion. */ Set() - : m_removed_slots(0), - m_occupied_and_removed_slots(0), - m_usable_slots(0), - m_slot_mask(0), - m_slots(1) + : removed_slots_(0), + occupied_and_removed_slots_(0), + usable_slots_(0), + slot_mask_(0), + slots_(1) { } @@ -196,13 +196,13 @@ class Set { Set(const Set &other) = default; Set(Set &&other) noexcept - : m_removed_slots(other.m_removed_slots), - m_occupied_and_removed_slots(other.m_occupied_and_removed_slots), - m_usable_slots(other.m_usable_slots), - m_slot_mask(other.m_slot_mask), - m_hash(std::move(other.m_hash)), - m_is_equal(std::move(other.m_is_equal)), - m_slots(std::move(other.m_slots)) + : removed_slots_(other.removed_slots_), + occupied_and_removed_slots_(other.occupied_and_removed_slots_), + usable_slots_(other.usable_slots_), + slot_mask_(other.slot_mask_), + hash_(std::move(other.hash_)), + is_equal_(std::move(other.is_equal_)), + slots_(std::move(other.slots_)) { other.~Set(); new (&other) Set(); @@ -239,11 +239,11 @@ class Set { */ void add_new(const Key &key) { - this->add_new__impl(key, m_hash(key)); + this->add_new__impl(key, hash_(key)); } void add_new(Key &&key) { - this->add_new__impl(std::move(key), m_hash(key)); + this->add_new__impl(std::move(key), hash_(key)); } /** @@ -266,7 +266,7 @@ class Set { */ template<typename ForwardKey> bool add_as(ForwardKey &&key) { - return this->add__impl(std::forward<ForwardKey>(key), m_hash(key)); + return this->add__impl(std::forward<ForwardKey>(key), hash_(key)); } /** @@ -309,7 +309,7 @@ class Set { */ template<typename ForwardKey> bool contains_as(const ForwardKey &key) const { - return this->contains__impl(key, m_hash(key)); + return this->contains__impl(key, hash_(key)); } /** @@ -327,7 +327,7 @@ class Set { */ template<typename ForwardKey> bool remove_as(const ForwardKey &key) { - return this->remove__impl(key, m_hash(key)); + return this->remove__impl(key, hash_(key)); } /** @@ -344,7 +344,7 @@ class Set { */ template<typename ForwardKey> void remove_contained_as(const ForwardKey &key) { - this->remove_contained__impl(key, m_hash(key)); + this->remove_contained__impl(key, hash_(key)); } /** @@ -356,20 +356,20 @@ class Set { */ class Iterator { private: - const Slot *m_slots; - uint32_t m_total_slots; - uint32_t m_current_slot; + const Slot *slots_; + uint32_t total_slots_; + uint32_t current_slot_; public: Iterator(const Slot *slots, uint32_t total_slots, uint32_t current_slot) - : m_slots(slots), m_total_slots(total_slots), m_current_slot(current_slot) + : slots_(slots), total_slots_(total_slots), current_slot_(current_slot) { } Iterator &operator++() { - while (++m_current_slot < m_total_slots) { - if (m_slots[m_current_slot].is_occupied()) { + while (++current_slot_ < total_slots_) { + if (slots_[current_slot_].is_occupied()) { break; } } @@ -378,22 +378,22 @@ class Set { const Key &operator*() const { - return *m_slots[m_current_slot].key(); + return *slots_[current_slot_].key(); } friend bool operator!=(const Iterator &a, const Iterator &b) { - BLI_assert(a.m_slots == b.m_slots); - BLI_assert(a.m_total_slots == b.m_total_slots); - return a.m_current_slot != b.m_current_slot; + BLI_assert(a.slots_ == b.slots_); + BLI_assert(a.total_slots_ == b.total_slots_); + return a.current_slot_ != b.current_slot_; } }; Iterator begin() const { - for (uint32_t i = 0; i < m_slots.size(); i++) { - if (m_slots[i].is_occupied()) { - return Iterator(m_slots.data(), m_slots.size(), i); + for (uint32_t i = 0; i < slots_.size(); i++) { + if (slots_[i].is_occupied()) { + return Iterator(slots_.data(), slots_.size(), i); } } return this->end(); @@ -401,7 +401,7 @@ class Set { Iterator end() const { - return Iterator(m_slots.data(), m_slots.size(), m_slots.size()); + return Iterator(slots_.data(), slots_.size(), slots_.size()); } /** @@ -419,7 +419,7 @@ class Set { */ uint32_t count_collisions(const Key &key) const { - return this->count_collisions__impl(key, m_hash(key)); + return this->count_collisions__impl(key, hash_(key)); } /** @@ -445,7 +445,7 @@ class Set { */ uint32_t size() const { - return m_occupied_and_removed_slots - m_removed_slots; + return occupied_and_removed_slots_ - removed_slots_; } /** @@ -453,7 +453,7 @@ class Set { */ bool is_empty() const { - return m_occupied_and_removed_slots == m_removed_slots; + return occupied_and_removed_slots_ == removed_slots_; } /** @@ -461,7 +461,7 @@ class Set { */ uint32_t capacity() const { - return m_slots.size(); + return slots_.size(); } /** @@ -469,7 +469,7 @@ class Set { */ uint32_t removed_amount() const { - return m_removed_slots; + return removed_slots_; } /** @@ -486,7 +486,7 @@ class Set { */ uint32_t size_in_bytes() const { - return sizeof(Slot) * m_slots.size(); + return sizeof(Slot) * slots_.size(); } /** @@ -495,7 +495,7 @@ class Set { */ void reserve(uint32_t n) { - if (m_usable_slots < n) { + if (usable_slots_ < n) { this->realloc_and_reinsert(n); } } @@ -530,7 +530,7 @@ class Set { BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots) { uint32_t total_slots, usable_slots; - m_max_load_factor.compute_total_and_usable_slots( + max_load_factor_.compute_total_and_usable_slots( SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots); uint32_t new_slot_mask = total_slots - 1; @@ -538,19 +538,19 @@ class Set { * Optimize the case when the set was empty beforehand. We can avoid some copies here. */ if (this->size() == 0) { - m_slots.~Array(); - new (&m_slots) SlotArray(total_slots); - m_removed_slots = 0; - m_occupied_and_removed_slots = 0; - m_usable_slots = usable_slots; - m_slot_mask = new_slot_mask; + slots_.~Array(); + new (&slots_) SlotArray(total_slots); + removed_slots_ = 0; + occupied_and_removed_slots_ = 0; + usable_slots_ = usable_slots; + slot_mask_ = new_slot_mask; return; } /* The grown array that we insert the keys into. */ SlotArray new_slots(total_slots); - for (Slot &slot : m_slots) { + for (Slot &slot : slots_) { if (slot.is_occupied()) { this->add_after_grow_and_destruct_old(slot, new_slots, new_slot_mask); } @@ -558,12 +558,12 @@ class Set { /* All occupied slots have been destructed already and empty/removed slots are assumed to be * trivially destructible. */ - m_slots.clear_without_destruct(); - m_slots = std::move(new_slots); - m_occupied_and_removed_slots -= m_removed_slots; - m_usable_slots = usable_slots; - m_removed_slots = 0; - m_slot_mask = new_slot_mask; + slots_.clear_without_destruct(); + slots_ = std::move(new_slots); + occupied_and_removed_slots_ -= removed_slots_; + usable_slots_ = usable_slots; + removed_slots_ = 0; + slot_mask_ = new_slot_mask; } void add_after_grow_and_destruct_old(Slot &old_slot, @@ -588,7 +588,7 @@ class Set { if (slot.is_empty()) { return false; } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return true; } } @@ -604,7 +604,7 @@ class Set { SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { slot.occupy(std::forward<ForwardKey>(key), hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return; } } @@ -618,10 +618,10 @@ class Set { SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { slot.occupy(std::forward<ForwardKey>(key), hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return true; } - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return false; } } @@ -631,9 +631,9 @@ class Set { template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash) { SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { slot.remove(); - m_removed_slots++; + removed_slots_++; return true; } if (slot.is_empty()) { @@ -646,10 +646,10 @@ class Set { template<typename ForwardKey> void remove_contained__impl(const ForwardKey &key, uint32_t hash) { BLI_assert(this->contains_as(key)); - m_removed_slots++; + removed_slots_++; SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { slot.remove(); return; } @@ -663,7 +663,7 @@ class Set { uint32_t collisions = 0; SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash)) { + if (slot.contains(key, is_equal_, hash)) { return collisions; } if (slot.is_empty()) { @@ -676,9 +676,9 @@ class Set { void ensure_can_add() { - if (m_occupied_and_removed_slots >= m_usable_slots) { + if (occupied_and_removed_slots_ >= usable_slots_) { this->realloc_and_reinsert(this->size() + 1); - BLI_assert(m_occupied_and_removed_slots < m_usable_slots); + BLI_assert(occupied_and_removed_slots_ < usable_slots_); } } }; @@ -690,77 +690,77 @@ class Set { template<typename Key> class StdUnorderedSetWrapper { private: using SetType = std::unordered_set<Key, blender::DefaultHash<Key>>; - SetType m_set; + SetType set_; public: uint32_t size() const { - return (uint32_t)m_set.size(); + return (uint32_t)set_.size(); } bool is_empty() const { - return m_set.empty(); + return set_.empty(); } void reserve(uint32_t n) { - m_set.reserve(n); + set_.reserve(n); } void add_new(const Key &key) { - m_set.insert(key); + set_.insert(key); } void add_new(Key &&key) { - m_set.insert(std::move(key)); + set_.insert(std::move(key)); } bool add(const Key &key) { - return m_set.insert(key).second; + return set_.insert(key).second; } bool add(Key &&key) { - return m_set.insert(std::move(key)).second; + return set_.insert(std::move(key)).second; } void add_multiple(Span<Key> keys) { for (const Key &key : keys) { - m_set.insert(key); + set_.insert(key); } } bool contains(const Key &key) const { - return m_set.find(key) != m_set.end(); + return set_.find(key) != set_.end(); } bool remove(const Key &key) { - return (bool)m_set.erase(key); + return (bool)set_.erase(key); } void remove_contained(const Key &key) { - return m_set.erase(key); + return set_.erase(key); } void clear() { - m_set.clear(); + set_.clear(); } typename SetType::iterator begin() const { - return m_set.begin(); + return set_.begin(); } typename SetType::iterator end() const { - return m_set.end(); + return set_.end(); } }; diff --git a/source/blender/blenlib/BLI_set_slots.hh b/source/blender/blenlib/BLI_set_slots.hh index 581e70ce628..379e81b7644 100644 --- a/source/blender/blenlib/BLI_set_slots.hh +++ b/source/blender/blenlib/BLI_set_slots.hh @@ -50,8 +50,8 @@ template<typename Key> class SimpleSetSlot { Removed = 2, }; - State m_state; - AlignedBuffer<sizeof(Key), alignof(Key)> m_buffer; + State state_; + AlignedBuffer<sizeof(Key), alignof(Key)> buffer_; public: /** @@ -59,7 +59,7 @@ template<typename Key> class SimpleSetSlot { */ SimpleSetSlot() { - m_state = Empty; + state_ = Empty; } /** @@ -67,7 +67,7 @@ template<typename Key> class SimpleSetSlot { */ ~SimpleSetSlot() { - if (m_state == Occupied) { + if (state_ == Occupied) { this->key()->~Key(); } } @@ -78,8 +78,8 @@ template<typename Key> class SimpleSetSlot { */ SimpleSetSlot(const SimpleSetSlot &other) { - m_state = other.m_state; - if (other.m_state == Occupied) { + state_ = other.state_; + if (other.state_ == Occupied) { new ((void *)this->key()) Key(*other.key()); } } @@ -91,8 +91,8 @@ template<typename Key> class SimpleSetSlot { */ SimpleSetSlot(SimpleSetSlot &&other) noexcept { - m_state = other.m_state; - if (other.m_state == Occupied) { + state_ = other.state_; + if (other.state_ == Occupied) { new ((void *)this->key()) Key(std::move(*other.key())); } } @@ -102,7 +102,7 @@ template<typename Key> class SimpleSetSlot { */ Key *key() { - return (Key *)m_buffer.ptr(); + return (Key *)buffer_.ptr(); } /** @@ -110,7 +110,7 @@ template<typename Key> class SimpleSetSlot { */ const Key *key() const { - return (const Key *)m_buffer.ptr(); + return (const Key *)buffer_.ptr(); } /** @@ -118,7 +118,7 @@ template<typename Key> class SimpleSetSlot { */ bool is_occupied() const { - return m_state == Occupied; + return state_ == Occupied; } /** @@ -126,7 +126,7 @@ template<typename Key> class SimpleSetSlot { */ bool is_empty() const { - return m_state == Empty; + return state_ == Empty; } /** @@ -147,7 +147,7 @@ template<typename Key> class SimpleSetSlot { { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_state = Occupied; + state_ = Occupied; new ((void *)this->key()) Key(std::move(*other.key())); other.key()->~Key(); } @@ -159,7 +159,7 @@ template<typename Key> class SimpleSetSlot { template<typename ForwardKey, typename IsEqual> bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const { - if (m_state == Occupied) { + if (state_ == Occupied) { return is_equal(key, *this->key()); } return false; @@ -172,7 +172,7 @@ template<typename Key> class SimpleSetSlot { template<typename ForwardKey> void occupy(ForwardKey &&key, uint32_t UNUSED(hash)) { BLI_assert(!this->is_occupied()); - m_state = Occupied; + state_ = Occupied; new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } @@ -182,7 +182,7 @@ template<typename Key> class SimpleSetSlot { void remove() { BLI_assert(this->is_occupied()); - m_state = Removed; + state_ = Removed; this->key()->~Key(); } }; @@ -199,73 +199,73 @@ template<typename Key> class HashedSetSlot { Removed = 2, }; - uint32_t m_hash; - State m_state; - AlignedBuffer<sizeof(Key), alignof(Key)> m_buffer; + uint32_t hash_; + State state_; + AlignedBuffer<sizeof(Key), alignof(Key)> buffer_; public: HashedSetSlot() { - m_state = Empty; + state_ = Empty; } ~HashedSetSlot() { - if (m_state == Occupied) { + if (state_ == Occupied) { this->key()->~Key(); } } HashedSetSlot(const HashedSetSlot &other) { - m_state = other.m_state; - if (other.m_state == Occupied) { - m_hash = other.m_hash; + state_ = other.state_; + if (other.state_ == Occupied) { + hash_ = other.hash_; new ((void *)this->key()) Key(*other.key()); } } HashedSetSlot(HashedSetSlot &&other) noexcept { - m_state = other.m_state; - if (other.m_state == Occupied) { - m_hash = other.m_hash; + state_ = other.state_; + if (other.state_ == Occupied) { + hash_ = other.hash_; new ((void *)this->key()) Key(std::move(*other.key())); } } Key *key() { - return (Key *)m_buffer.ptr(); + return (Key *)buffer_.ptr(); } const Key *key() const { - return (const Key *)m_buffer.ptr(); + return (const Key *)buffer_.ptr(); } bool is_occupied() const { - return m_state == Occupied; + return state_ == Occupied; } bool is_empty() const { - return m_state == Empty; + return state_ == Empty; } template<typename Hash> uint32_t get_hash(const Hash &UNUSED(hash)) const { BLI_assert(this->is_occupied()); - return m_hash; + return hash_; } void relocate_occupied_here(HashedSetSlot &other, uint32_t hash) { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_state = Occupied; - m_hash = hash; + state_ = Occupied; + hash_ = hash; new ((void *)this->key()) Key(std::move(*other.key())); other.key()->~Key(); } @@ -273,9 +273,9 @@ template<typename Key> class HashedSetSlot { template<typename ForwardKey, typename IsEqual> bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t hash) const { - /* m_hash might be uninitialized here, but that is ok. */ - if (m_hash == hash) { - if (m_state == Occupied) { + /* hash_ might be uninitialized here, but that is ok. */ + if (hash_ == hash) { + if (state_ == Occupied) { return is_equal(key, *this->key()); } } @@ -285,15 +285,15 @@ template<typename Key> class HashedSetSlot { template<typename ForwardKey> void occupy(ForwardKey &&key, uint32_t hash) { BLI_assert(!this->is_occupied()); - m_state = Occupied; - m_hash = hash; + state_ = Occupied; + hash_ = hash; new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } void remove() { BLI_assert(this->is_occupied()); - m_state = Removed; + state_ = Removed; this->key()->~Key(); } }; @@ -308,7 +308,7 @@ template<typename Key> class HashedSetSlot { */ template<typename Key, typename KeyInfo> class IntrusiveSetSlot { private: - Key m_key = KeyInfo::get_empty(); + Key key_ = KeyInfo::get_empty(); public: IntrusiveSetSlot() = default; @@ -318,43 +318,43 @@ template<typename Key, typename KeyInfo> class IntrusiveSetSlot { Key *key() { - return &m_key; + return &key_; } const Key *key() const { - return &m_key; + return &key_; } bool is_occupied() const { - return KeyInfo::is_not_empty_or_removed(m_key); + return KeyInfo::is_not_empty_or_removed(key_); } bool is_empty() const { - return KeyInfo::is_empty(m_key); + return KeyInfo::is_empty(key_); } template<typename Hash> uint32_t get_hash(const Hash &hash) const { BLI_assert(this->is_occupied()); - return hash(m_key); + return hash(key_); } void relocate_occupied_here(IntrusiveSetSlot &other, uint32_t UNUSED(hash)) { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_key = std::move(other.m_key); - other.m_key.~Key(); + key_ = std::move(other.key_); + other.key_.~Key(); } template<typename ForwardKey, typename IsEqual> bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const { BLI_assert(KeyInfo::is_not_empty_or_removed(key)); - return is_equal(m_key, key); + return is_equal(key_, key); } template<typename ForwardKey> void occupy(ForwardKey &&key, uint32_t UNUSED(hash)) @@ -362,13 +362,13 @@ template<typename Key, typename KeyInfo> class IntrusiveSetSlot { BLI_assert(!this->is_occupied()); BLI_assert(KeyInfo::is_not_empty_or_removed(key)); - m_key = std::forward<ForwardKey>(key); + key_ = std::forward<ForwardKey>(key); } void remove() { BLI_assert(this->is_occupied()); - KeyInfo::remove(m_key); + KeyInfo::remove(key_); } }; diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index ce4e90d5e16..cbf420c2368 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -87,8 +87,8 @@ namespace blender { */ template<typename T> class Span { private: - const T *m_start = nullptr; - uint m_size = 0; + const T *start_ = nullptr; + uint size_ = 0; public: /** @@ -96,7 +96,7 @@ template<typename T> class Span { */ Span() = default; - Span(const T *start, uint size) : m_start(start), m_size(size) + Span(const T *start, uint size) : start_(start), size_(size) { } @@ -141,7 +141,7 @@ template<typename T> class Span { Span slice(uint start, uint size) const { BLI_assert(start + size <= this->size() || size == 0); - return Span(m_start + start, size); + return Span(start_ + start, size); } Span slice(IndexRange range) const @@ -195,17 +195,17 @@ template<typename T> class Span { */ const T *data() const { - return m_start; + return start_; } const T *begin() const { - return m_start; + return start_; } const T *end() const { - return m_start + m_size; + return start_ + size_; } /** @@ -214,8 +214,8 @@ template<typename T> class Span { */ const T &operator[](uint index) const { - BLI_assert(index < m_size); - return m_start[index]; + BLI_assert(index < size_); + return start_[index]; } /** @@ -223,7 +223,7 @@ template<typename T> class Span { */ uint size() const { - return m_size; + return size_; } /** @@ -231,7 +231,7 @@ template<typename T> class Span { */ bool is_empty() const { - return m_size == 0; + return size_ == 0; } /** @@ -239,7 +239,7 @@ template<typename T> class Span { */ uint size_in_bytes() const { - return sizeof(T) * m_size; + return sizeof(T) * size_; } /** @@ -286,8 +286,8 @@ template<typename T> class Span { */ const T &first() const { - BLI_assert(m_size > 0); - return m_start[0]; + BLI_assert(size_ > 0); + return start_[0]; } /** @@ -296,8 +296,8 @@ template<typename T> class Span { */ const T &last() const { - BLI_assert(m_size > 0); - return m_start[m_size - 1]; + BLI_assert(size_ > 0); + return start_[size_ - 1]; } /** @@ -306,8 +306,8 @@ template<typename T> class Span { */ T get(uint index, const T &fallback) const { - if (index < m_size) { - return m_start[index]; + if (index < size_) { + return start_[index]; } return fallback; } @@ -320,12 +320,12 @@ template<typename T> class Span { { /* The size should really be smaller than that. If it is not, the calling code should be * changed. */ - BLI_assert(m_size < 1000); + BLI_assert(size_ < 1000); - for (uint i = 0; i < m_size; i++) { - const T &value = m_start[i]; - for (uint j = i + 1; j < m_size; j++) { - if (value == m_start[j]) { + for (uint i = 0; i < size_; i++) { + const T &value = start_[i]; + for (uint j = i + 1; j < size_; j++) { + if (value == start_[j]) { return true; } } @@ -342,10 +342,10 @@ template<typename T> class Span { { /* The size should really be smaller than that. If it is not, the calling code should be * changed. */ - BLI_assert(m_size < 1000); + BLI_assert(size_ < 1000); - for (uint i = 0; i < m_size; i++) { - const T &value = m_start[i]; + for (uint i = 0; i < size_; i++) { + const T &value = start_[i]; if (other.contains(value)) { return true; } @@ -369,8 +369,8 @@ template<typename T> class Span { */ int first_index_try(const T &search_value) const { - for (uint i = 0; i < m_size; i++) { - if (m_start[i] == search_value) { + for (uint i = 0; i < size_; i++) { + if (start_[i] == search_value) { return i; } } @@ -383,7 +383,7 @@ template<typename T> class Span { */ IndexRange index_range() const { - return IndexRange(m_size); + return IndexRange(size_); } /** @@ -391,9 +391,9 @@ template<typename T> class Span { */ template<typename NewT> Span<NewT> cast() const { - BLI_assert((m_size * sizeof(T)) % sizeof(NewT) == 0); - uint new_size = m_size * sizeof(T) / sizeof(NewT); - return Span<NewT>(reinterpret_cast<const NewT *>(m_start), new_size); + BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0); + uint new_size = size_ * sizeof(T) / sizeof(NewT); + return Span<NewT>(reinterpret_cast<const NewT *>(start_), new_size); } /** @@ -402,7 +402,7 @@ template<typename T> class Span { */ template<typename PrintLineF> void print_as_lines(std::string name, PrintLineF print_line) const { - std::cout << "Span: " << name << " \tSize:" << m_size << '\n'; + std::cout << "Span: " << name << " \tSize:" << size_ << '\n'; for (const T &value : *this) { std::cout << " "; print_line(value); @@ -426,13 +426,13 @@ template<typename T> class Span { */ template<typename T> class MutableSpan { private: - T *m_start; - uint m_size; + T *start_; + uint size_; public: MutableSpan() = default; - MutableSpan(T *start, uint size) : m_start(start), m_size(size) + MutableSpan(T *start, uint size) : start_(start), size_(size) { } @@ -461,7 +461,7 @@ template<typename T> class MutableSpan { operator Span<T>() const { - return Span<T>(m_start, m_size); + return Span<T>(start_, size_); } /** @@ -469,7 +469,7 @@ template<typename T> class MutableSpan { */ uint size() const { - return m_size; + return size_; } /** @@ -477,7 +477,7 @@ template<typename T> class MutableSpan { */ void fill(const T &value) { - initialized_fill_n(m_start, m_size, value); + initialized_fill_n(start_, size_, value); } /** @@ -487,8 +487,8 @@ template<typename T> class MutableSpan { void fill_indices(Span<uint> indices, const T &value) { for (uint i : indices) { - BLI_assert(i < m_size); - m_start[i] = value; + BLI_assert(i < size_); + start_[i] = value; } } @@ -498,23 +498,23 @@ template<typename T> class MutableSpan { */ T *data() const { - return m_start; + return start_; } T *begin() const { - return m_start; + return start_; } T *end() const { - return m_start + m_size; + return start_ + size_; } T &operator[](uint index) const { BLI_assert(index < this->size()); - return m_start[index]; + return start_[index]; } /** @@ -524,7 +524,7 @@ template<typename T> class MutableSpan { MutableSpan slice(uint start, uint length) const { BLI_assert(start + length <= this->size()); - return MutableSpan(m_start + start, length); + return MutableSpan(start_ + start, length); } /** @@ -573,7 +573,7 @@ template<typename T> class MutableSpan { */ Span<T> as_span() const { - return Span<T>(m_start, m_size); + return Span<T>(start_, size_); } /** @@ -582,7 +582,7 @@ template<typename T> class MutableSpan { */ IndexRange index_range() const { - return IndexRange(m_size); + return IndexRange(size_); } /** @@ -591,8 +591,8 @@ template<typename T> class MutableSpan { */ T &last() const { - BLI_assert(m_size > 0); - return m_start[m_size - 1]; + BLI_assert(size_ > 0); + return start_[size_ - 1]; } /** @@ -600,9 +600,9 @@ template<typename T> class MutableSpan { */ template<typename NewT> MutableSpan<NewT> cast() const { - BLI_assert((m_size * sizeof(T)) % sizeof(NewT) == 0); - uint new_size = m_size * sizeof(T) / sizeof(NewT); - return MutableSpan<NewT>(reinterpret_cast<NewT *>(m_start), new_size); + BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0); + uint new_size = size_ * sizeof(T) / sizeof(NewT); + return MutableSpan<NewT>(reinterpret_cast<NewT *>(start_), new_size); } }; diff --git a/source/blender/blenlib/BLI_stack.hh b/source/blender/blenlib/BLI_stack.hh index 2170b8b23bc..021fa43ed7d 100644 --- a/source/blender/blenlib/BLI_stack.hh +++ b/source/blender/blenlib/BLI_stack.hh @@ -91,48 +91,48 @@ class Stack { * Points to one element after top-most value in the stack. * * Invariant: - * If m_size == 0 - * then: m_top == m_inline_chunk.begin - * else: &peek() == m_top - 1; + * If size_ == 0 + * then: top_ == inline_chunk_.begin + * else: &peek() == top_ - 1; */ - T *m_top; + T *top_; - /** Points to the chunk that references the memory pointed to by m_top. */ - Chunk *m_top_chunk; + /** Points to the chunk that references the memory pointed to by top_. */ + Chunk *top_chunk_; /** * Number of elements in the entire stack. The sum of initialized element counts in the chunks. */ - uint m_size; + uint size_; /** The buffer used to implement small object optimization. */ - AlignedBuffer<sizeof(T) * InlineBufferCapacity, alignof(T)> m_inline_buffer; + AlignedBuffer<sizeof(T) * InlineBufferCapacity, alignof(T)> inline_buffer_; /** * A chunk referencing the inline buffer. This is always the bottom-most chunk. - * So m_inline_chunk.below == nullptr. + * So inline_chunk_.below == nullptr. */ - Chunk m_inline_chunk; + Chunk inline_chunk_; /** Used for allocations when the inline buffer is not large enough. */ - Allocator m_allocator; + Allocator allocator_; public: /** * Initialize an empty stack. No heap allocation is done. */ - Stack(Allocator allocator = {}) : m_allocator(allocator) + Stack(Allocator allocator = {}) : allocator_(allocator) { T *inline_buffer = this->inline_buffer(); - m_inline_chunk.below = nullptr; - m_inline_chunk.above = nullptr; - m_inline_chunk.begin = inline_buffer; - m_inline_chunk.capacity_end = inline_buffer + InlineBufferCapacity; + inline_chunk_.below = nullptr; + inline_chunk_.above = nullptr; + inline_chunk_.begin = inline_buffer; + inline_chunk_.capacity_end = inline_buffer + InlineBufferCapacity; - m_top = inline_buffer; - m_top_chunk = &m_inline_chunk; - m_size = 0; + top_ = inline_buffer; + top_chunk_ = &inline_chunk_; + size_ = 0; } /** @@ -157,46 +157,45 @@ class Stack { { } - Stack(const Stack &other) : Stack(other.m_allocator) + Stack(const Stack &other) : Stack(other.allocator_) { - for (const Chunk *chunk = &other.m_inline_chunk; chunk; chunk = chunk->above) { + for (const Chunk *chunk = &other.inline_chunk_; chunk; chunk = chunk->above) { const T *begin = chunk->begin; - const T *end = (chunk == other.m_top_chunk) ? other.m_top : chunk->capacity_end; + const T *end = (chunk == other.top_chunk_) ? other.top_ : chunk->capacity_end; this->push_multiple(Span<T>(begin, end - begin)); } } - Stack(Stack &&other) noexcept : Stack(other.m_allocator) + Stack(Stack &&other) noexcept : Stack(other.allocator_) { - uninitialized_relocate_n(other.inline_buffer(), - std::min(other.m_size, InlineBufferCapacity), - this->inline_buffer()); + uninitialized_relocate_n( + other.inline_buffer(), std::min(other.size_, InlineBufferCapacity), this->inline_buffer()); - m_inline_chunk.above = other.m_inline_chunk.above; - m_size = other.m_size; + inline_chunk_.above = other.inline_chunk_.above; + size_ = other.size_; - if (m_size <= InlineBufferCapacity) { - m_top_chunk = &m_inline_chunk; - m_top = this->inline_buffer() + m_size; + if (size_ <= InlineBufferCapacity) { + top_chunk_ = &inline_chunk_; + top_ = this->inline_buffer() + size_; } else { - m_top_chunk = other.m_top_chunk; - m_top = other.m_top; + top_chunk_ = other.top_chunk_; + top_ = other.top_; } - other.m_size = 0; - other.m_inline_chunk.above = nullptr; - other.m_top_chunk = &other.m_inline_chunk; - other.m_top = other.m_top_chunk->begin; + other.size_ = 0; + other.inline_chunk_.above = nullptr; + other.top_chunk_ = &other.inline_chunk_; + other.top_ = other.top_chunk_->begin; } ~Stack() { this->destruct_all_elements(); Chunk *above_chunk; - for (Chunk *chunk = m_inline_chunk.above; chunk; chunk = above_chunk) { + for (Chunk *chunk = inline_chunk_.above; chunk; chunk = above_chunk) { above_chunk = chunk->above; - m_allocator.deallocate(chunk); + allocator_.deallocate(chunk); } } @@ -229,21 +228,21 @@ class Stack { */ void push(const T &value) { - if (m_top == m_top_chunk->capacity_end) { + if (top_ == top_chunk_->capacity_end) { this->activate_next_chunk(1); } - new (m_top) T(value); - m_top++; - m_size++; + new (top_) T(value); + top_++; + size_++; } void push(T &&value) { - if (m_top == m_top_chunk->capacity_end) { + if (top_ == top_chunk_->capacity_end) { this->activate_next_chunk(1); } - new (m_top) T(std::move(value)); - m_top++; - m_size++; + new (top_) T(std::move(value)); + top_++; + size_++; } /** @@ -252,16 +251,16 @@ class Stack { */ T pop() { - BLI_assert(m_size > 0); - m_top--; - T value = std::move(*m_top); - m_top->~T(); - m_size--; - - if (m_top == m_top_chunk->begin) { - if (m_top_chunk->below != nullptr) { - m_top_chunk = m_top_chunk->below; - m_top = m_top_chunk->capacity_end; + BLI_assert(size_ > 0); + top_--; + T value = std::move(*top_); + top_->~T(); + size_--; + + if (top_ == top_chunk_->begin) { + if (top_chunk_->below != nullptr) { + top_chunk_ = top_chunk_->below; + top_ = top_chunk_->capacity_end; } } return value; @@ -273,15 +272,15 @@ class Stack { */ T &peek() { - BLI_assert(m_size > 0); - BLI_assert(m_top > m_top_chunk->begin); - return *(m_top - 1); + BLI_assert(size_ > 0); + BLI_assert(top_ > top_chunk_->begin); + return *(top_ - 1); } const T &peek() const { - BLI_assert(m_size > 0); - BLI_assert(m_top > m_top_chunk->begin); - return *(m_top - 1); + BLI_assert(size_ > 0); + BLI_assert(top_ > top_chunk_->begin); + return *(top_ - 1); } /** @@ -293,19 +292,19 @@ class Stack { { Span<T> remaining_values = values; while (!remaining_values.is_empty()) { - if (m_top == m_top_chunk->capacity_end) { + if (top_ == top_chunk_->capacity_end) { this->activate_next_chunk(remaining_values.size()); } - uint remaining_capacity = m_top_chunk->capacity_end - m_top; + uint remaining_capacity = top_chunk_->capacity_end - top_; uint amount = std::min(remaining_values.size(), remaining_capacity); - uninitialized_copy_n(remaining_values.data(), amount, m_top); - m_top += amount; + uninitialized_copy_n(remaining_values.data(), amount, top_); + top_ += amount; remaining_values = remaining_values.drop_front(amount); } - m_size += values.size(); + size_ += values.size(); } /** @@ -313,7 +312,7 @@ class Stack { */ bool is_empty() const { - return m_size == 0; + return size_ == 0; } /** @@ -321,7 +320,7 @@ class Stack { */ uint size() const { - return m_size; + return size_; } /** @@ -331,18 +330,18 @@ class Stack { void clear() { this->destruct_all_elements(); - m_top_chunk = &m_inline_chunk; - m_top = m_top_chunk->begin; + top_chunk_ = &inline_chunk_; + top_ = top_chunk_->begin; } private: T *inline_buffer() const { - return (T *)m_inline_buffer.ptr(); + return (T *)inline_buffer_.ptr(); } /** - * Changes m_top_chunk to point to a new chunk that is above the current one. The new chunk might + * Changes top_chunk_ to point to a new chunk that is above the current one. The new chunk might * be smaller than the given size_hint. This happens when a chunk that has been allocated before * is reused. The size of the new chunk will be at least one. * @@ -350,12 +349,12 @@ class Stack { */ void activate_next_chunk(uint size_hint) { - BLI_assert(m_top == m_top_chunk->capacity_end); - if (m_top_chunk->above == nullptr) { - uint new_capacity = std::max(size_hint, m_top_chunk->capacity() * 2 + 10); + BLI_assert(top_ == top_chunk_->capacity_end); + if (top_chunk_->above == nullptr) { + uint new_capacity = std::max(size_hint, top_chunk_->capacity() * 2 + 10); /* Do a single memory allocation for the Chunk and the array it references. */ - void *buffer = m_allocator.allocate( + void *buffer = allocator_.allocate( sizeof(Chunk) + sizeof(T) * new_capacity + alignof(T), alignof(Chunk), AT); void *chunk_buffer = buffer; void *data_buffer = (void *)(((uintptr_t)buffer + sizeof(Chunk) + alignof(T) - 1) & @@ -365,19 +364,19 @@ class Stack { new_chunk->begin = (T *)data_buffer; new_chunk->capacity_end = new_chunk->begin + new_capacity; new_chunk->above = nullptr; - new_chunk->below = m_top_chunk; - m_top_chunk->above = new_chunk; + new_chunk->below = top_chunk_; + top_chunk_->above = new_chunk; } - m_top_chunk = m_top_chunk->above; - m_top = m_top_chunk->begin; + top_chunk_ = top_chunk_->above; + top_ = top_chunk_->begin; } void destruct_all_elements() { - for (T *value = m_top_chunk->begin; value != m_top; value++) { + for (T *value = top_chunk_->begin; value != top_; value++) { value->~T(); } - for (Chunk *chunk = m_top_chunk->below; chunk; chunk = chunk->below) { + for (Chunk *chunk = top_chunk_->below; chunk; chunk = chunk->below) { for (T *value = chunk->begin; value != chunk->capacity_end; value++) { value->~T(); } diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index 62755de19af..01a76aa3edb 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -59,10 +59,10 @@ class StringRef; */ class StringRefBase { protected: - const char *m_data; - uint m_size; + const char *data_; + uint size_; - StringRefBase(const char *data, uint size) : m_data(data), m_size(size) + StringRefBase(const char *data, uint size) : data_(data), size_(size) { } @@ -72,7 +72,7 @@ class StringRefBase { */ uint size() const { - return m_size; + return size_; } /** @@ -80,12 +80,12 @@ class StringRefBase { */ const char *data() const { - return m_data; + return data_; } operator Span<char>() const { - return Span<char>(m_data, m_size); + return Span<char>(data_, size_); } /** @@ -94,17 +94,17 @@ class StringRefBase { */ operator std::string() const { - return std::string(m_data, m_size); + return std::string(data_, size_); } const char *begin() const { - return m_data; + return data_; } const char *end() const { - return m_data + m_size; + return data_ + size_; } /** @@ -114,8 +114,8 @@ class StringRefBase { */ void unsafe_copy(char *dst) const { - memcpy(dst, m_data, m_size); - dst[m_size] = '\0'; + memcpy(dst, data_, size_); + dst[size_] = '\0'; } /** @@ -124,7 +124,7 @@ class StringRefBase { */ void copy(char *dst, uint dst_size) const { - if (m_size < dst_size) { + if (size_ < dst_size) { this->unsafe_copy(dst); } else { @@ -171,7 +171,7 @@ class StringRefNull : public StringRefBase { StringRefNull(const char *str) : StringRefBase(str, (uint)strlen(str)) { BLI_assert(str != NULL); - BLI_assert(m_data[m_size] == '\0'); + BLI_assert(data_[size_] == '\0'); } /** @@ -197,8 +197,8 @@ class StringRefNull : public StringRefBase { char operator[](uint index) const { /* Use '<=' instead of just '<', so that the null character can be accessed as well. */ - BLI_assert(index <= m_size); - return m_data[index]; + BLI_assert(index <= size_); + return data_[index]; } }; @@ -252,8 +252,8 @@ class StringRef : public StringRefBase { */ StringRef drop_prefix(uint n) const { - BLI_assert(n <= m_size); - return StringRef(m_data + n, m_size - n); + BLI_assert(n <= size_); + return StringRef(data_ + n, size_ - n); } /** @@ -271,8 +271,8 @@ class StringRef : public StringRefBase { */ char operator[](uint index) const { - BLI_assert(index < m_size); - return m_data[index]; + BLI_assert(index < size_); + return data_[index]; } }; @@ -318,11 +318,11 @@ inline bool operator!=(StringRef a, StringRef b) */ inline bool StringRefBase::startswith(StringRef prefix) const { - if (m_size < prefix.m_size) { + if (size_ < prefix.size_) { return false; } - for (uint i = 0; i < prefix.m_size; i++) { - if (m_data[i] != prefix.m_data[i]) { + for (uint i = 0; i < prefix.size_; i++) { + if (data_[i] != prefix.data_[i]) { return false; } } @@ -334,12 +334,12 @@ inline bool StringRefBase::startswith(StringRef prefix) const */ inline bool StringRefBase::endswith(StringRef suffix) const { - if (m_size < suffix.m_size) { + if (size_ < suffix.size_) { return false; } - uint offset = m_size - suffix.m_size; - for (uint i = 0; i < suffix.m_size; i++) { - if (m_data[offset + i] != suffix.m_data[i]) { + uint offset = size_ - suffix.size_; + for (uint i = 0; i < suffix.size_; i++) { + if (data_[offset + i] != suffix.data_[i]) { return false; } } @@ -351,8 +351,8 @@ inline bool StringRefBase::endswith(StringRef suffix) const */ inline StringRef StringRefBase::substr(uint start, uint size) const { - BLI_assert(start + size <= m_size); - return StringRef(m_data + start, size); + BLI_assert(start + size <= size_); + return StringRef(data_ + start, size); } } // namespace blender diff --git a/source/blender/blenlib/BLI_timeit.hh b/source/blender/blenlib/BLI_timeit.hh index 711a7f16ab4..89d3f2369ea 100644 --- a/source/blender/blenlib/BLI_timeit.hh +++ b/source/blender/blenlib/BLI_timeit.hh @@ -34,21 +34,21 @@ void print_duration(Nanoseconds duration); class ScopedTimer { private: - std::string m_name; - TimePoint m_start; + std::string name_; + TimePoint start_; public: - ScopedTimer(std::string name) : m_name(std::move(name)) + ScopedTimer(std::string name) : name_(std::move(name)) { - m_start = Clock::now(); + start_ = Clock::now(); } ~ScopedTimer() { TimePoint end = Clock::now(); - Nanoseconds duration = end - m_start; + Nanoseconds duration = end - start_; - std::cout << "Timer '" << m_name << "' took "; + std::cout << "Timer '" << name_ << "' took "; print_duration(duration); std::cout << '\n'; } diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index c5f65d54288..1d161c419c8 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -84,15 +84,15 @@ class Vector { * * The pointers might point to the memory in the inline buffer. */ - T *m_begin; - T *m_end; - T *m_capacity_end; + T *begin_; + T *end_; + T *capacity_end_; /** Used for allocations when the inline buffer is too small. */ - Allocator m_allocator; + Allocator allocator_; /** A placeholder buffer that will remain uninitialized until it is used. */ - AlignedBuffer<(uint)sizeof(T) * InlineBufferCapacity, (uint)alignof(T)> m_inline_buffer; + AlignedBuffer<(uint)sizeof(T) * InlineBufferCapacity, (uint)alignof(T)> inline_buffer_; /** * Store the size of the vector explicitly in debug builds. Otherwise you'd always have to call @@ -100,8 +100,8 @@ class Vector { * annoying. Knowing the size of a vector is often quite essential when debugging some code. */ #ifndef NDEBUG - uint m_debug_size; -# define UPDATE_VECTOR_SIZE(ptr) (ptr)->m_debug_size = (uint)((ptr)->m_end - (ptr)->m_begin) + uint debug_size_; +# define UPDATE_VECTOR_SIZE(ptr) (ptr)->debug_size_ = (uint)((ptr)->end_ - (ptr)->begin_) #else # define UPDATE_VECTOR_SIZE(ptr) ((void)0) #endif @@ -120,9 +120,9 @@ class Vector { */ Vector() { - m_begin = this->inline_buffer(); - m_end = m_begin; - m_capacity_end = m_begin + InlineBufferCapacity; + begin_ = this->inline_buffer(); + end_ = begin_; + capacity_end_ = begin_ + InlineBufferCapacity; UPDATE_VECTOR_SIZE(this); } @@ -143,7 +143,7 @@ class Vector { { this->reserve(size); this->increase_size_by_unchecked(size); - blender::uninitialized_fill_n(m_begin, size, value); + blender::uninitialized_fill_n(begin_, size, value); } /** @@ -164,7 +164,7 @@ class Vector { uint size = values.size(); this->reserve(size); this->increase_size_by_unchecked(size); - blender::uninitialized_copy_n(values.data(), size, m_begin); + blender::uninitialized_copy_n(values.data(), size, begin_); } /** @@ -198,7 +198,7 @@ class Vector { * Create a copy of another vector. The other vector will not be changed. If the other vector has * less than InlineBufferCapacity elements, no allocation will be made. */ - Vector(const Vector &other) : m_allocator(other.m_allocator) + Vector(const Vector &other) : allocator_(other.allocator_) { this->init_copy_from_other_vector(other); } @@ -209,7 +209,7 @@ class Vector { */ template<uint OtherInlineBufferCapacity> Vector(const Vector<T, OtherInlineBufferCapacity, Allocator> &other) - : m_allocator(other.m_allocator) + : allocator_(other.allocator_) { this->init_copy_from_other_vector(other); } @@ -220,57 +220,57 @@ class Vector { */ template<uint OtherInlineBufferCapacity> Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept - : m_allocator(other.m_allocator) + : allocator_(other.allocator_) { uint size = other.size(); if (other.is_inline()) { if (size <= InlineBufferCapacity) { /* Copy between inline buffers. */ - m_begin = this->inline_buffer(); - m_end = m_begin + size; - m_capacity_end = m_begin + InlineBufferCapacity; - uninitialized_relocate_n(other.m_begin, size, m_begin); + begin_ = this->inline_buffer(); + end_ = begin_ + size; + capacity_end_ = begin_ + InlineBufferCapacity; + uninitialized_relocate_n(other.begin_, size, begin_); } else { /* Copy from inline buffer to newly allocated buffer. */ uint capacity = size; - m_begin = (T *)m_allocator.allocate(sizeof(T) * capacity, alignof(T), AT); - m_end = m_begin + size; - m_capacity_end = m_begin + capacity; - uninitialized_relocate_n(other.m_begin, size, m_begin); + begin_ = (T *)allocator_.allocate(sizeof(T) * capacity, alignof(T), AT); + end_ = begin_ + size; + capacity_end_ = begin_ + capacity; + uninitialized_relocate_n(other.begin_, size, begin_); } } else { /* Steal the pointer. */ - m_begin = other.m_begin; - m_end = other.m_end; - m_capacity_end = other.m_capacity_end; + begin_ = other.begin_; + end_ = other.end_; + capacity_end_ = other.capacity_end_; } - other.m_begin = other.inline_buffer(); - other.m_end = other.m_begin; - other.m_capacity_end = other.m_begin + OtherInlineBufferCapacity; + other.begin_ = other.inline_buffer(); + other.end_ = other.begin_; + other.capacity_end_ = other.begin_ + OtherInlineBufferCapacity; UPDATE_VECTOR_SIZE(this); UPDATE_VECTOR_SIZE(&other); } ~Vector() { - destruct_n(m_begin, this->size()); + destruct_n(begin_, this->size()); if (!this->is_inline()) { - m_allocator.deallocate(m_begin); + allocator_.deallocate(begin_); } } operator Span<T>() const { - return Span<T>(m_begin, this->size()); + return Span<T>(begin_, this->size()); } operator MutableSpan<T>() { - return MutableSpan<T>(m_begin, this->size()); + return MutableSpan<T>(begin_, this->size()); } Span<T> as_span() const @@ -332,12 +332,12 @@ class Vector { uint old_size = this->size(); if (new_size > old_size) { this->reserve(new_size); - default_construct_n(m_begin + old_size, new_size - old_size); + default_construct_n(begin_ + old_size, new_size - old_size); } else { - destruct_n(m_begin + new_size, old_size - new_size); + destruct_n(begin_ + new_size, old_size - new_size); } - m_end = m_begin + new_size; + end_ = begin_ + new_size; UPDATE_VECTOR_SIZE(this); } @@ -352,12 +352,12 @@ class Vector { uint old_size = this->size(); if (new_size > old_size) { this->reserve(new_size); - uninitialized_fill_n(m_begin + old_size, new_size - old_size, value); + uninitialized_fill_n(begin_ + old_size, new_size - old_size, value); } else { - destruct_n(m_begin + new_size, old_size - new_size); + destruct_n(begin_ + new_size, old_size - new_size); } - m_end = m_begin + new_size; + end_ = begin_ + new_size; UPDATE_VECTOR_SIZE(this); } @@ -367,8 +367,8 @@ class Vector { */ void clear() { - destruct_n(m_begin, this->size()); - m_end = m_begin; + destruct_n(begin_, this->size()); + end_ = begin_; UPDATE_VECTOR_SIZE(this); } @@ -378,14 +378,14 @@ class Vector { */ void clear_and_make_inline() { - destruct_n(m_begin, this->size()); + destruct_n(begin_, this->size()); if (!this->is_inline()) { - m_allocator.deallocate(m_begin); + allocator_.deallocate(begin_); } - m_begin = this->inline_buffer(); - m_end = m_begin; - m_capacity_end = m_begin + InlineBufferCapacity; + begin_ = this->inline_buffer(); + end_ = begin_; + capacity_end_ = begin_ + InlineBufferCapacity; UPDATE_VECTOR_SIZE(this); } @@ -436,16 +436,16 @@ class Vector { */ void append_unchecked(const T &value) { - BLI_assert(m_end < m_capacity_end); - new (m_end) T(value); - m_end++; + BLI_assert(end_ < capacity_end_); + new (end_) T(value); + end_++; UPDATE_VECTOR_SIZE(this); } void append_unchecked(T &&value) { - BLI_assert(m_end < m_capacity_end); - new (m_end) T(std::move(value)); - m_end++; + BLI_assert(end_ < capacity_end_); + new (end_) T(std::move(value)); + end_++; UPDATE_VECTOR_SIZE(this); } @@ -456,7 +456,7 @@ class Vector { void append_n_times(const T &value, uint n) { this->reserve(this->size() + n); - blender::uninitialized_fill_n(m_end, n, value); + blender::uninitialized_fill_n(end_, n, value); this->increase_size_by_unchecked(n); } @@ -468,8 +468,8 @@ class Vector { */ void increase_size_by_unchecked(uint n) { - BLI_assert(m_end + n <= m_capacity_end); - m_end += n; + BLI_assert(end_ + n <= capacity_end_); + end_ += n; UPDATE_VECTOR_SIZE(this); } @@ -510,9 +510,9 @@ class Vector { } void extend_unchecked(const T *start, uint amount) { - BLI_assert(m_begin + amount <= m_capacity_end); - blender::uninitialized_copy_n(start, amount, m_end); - m_end += amount; + BLI_assert(begin_ + amount <= capacity_end_); + blender::uninitialized_copy_n(start, amount, end_); + end_ += amount; UPDATE_VECTOR_SIZE(this); } @@ -523,12 +523,12 @@ class Vector { const T &last() const { BLI_assert(this->size() > 0); - return *(m_end - 1); + return *(end_ - 1); } T &last() { BLI_assert(this->size() > 0); - return *(m_end - 1); + return *(end_ - 1); } /** @@ -536,7 +536,7 @@ class Vector { */ void fill(const T &value) { - initialized_fill_n(m_begin, this->size(), value); + initialized_fill_n(begin_, this->size(), value); } /** @@ -552,8 +552,8 @@ class Vector { */ uint size() const { - BLI_assert(m_debug_size == (uint)(m_end - m_begin)); - return (uint)(m_end - m_begin); + BLI_assert(debug_size_ == (uint)(end_ - begin_)); + return (uint)(end_ - begin_); } /** @@ -563,7 +563,7 @@ class Vector { */ bool is_empty() const { - return m_begin == m_end; + return begin_ == end_; } /** @@ -573,8 +573,8 @@ class Vector { void remove_last() { BLI_assert(!this->is_empty()); - m_end--; - m_end->~T(); + end_--; + end_->~T(); UPDATE_VECTOR_SIZE(this); } @@ -587,9 +587,9 @@ class Vector { T pop_last() { BLI_assert(!this->is_empty()); - m_end--; - T value = std::move(*m_end); - m_end->~T(); + end_--; + T value = std::move(*end_); + end_->~T(); UPDATE_VECTOR_SIZE(this); return value; } @@ -601,12 +601,12 @@ class Vector { void remove_and_reorder(uint index) { BLI_assert(index < this->size()); - T *element_to_remove = m_begin + index; - m_end--; - if (element_to_remove < m_end) { - *element_to_remove = std::move(*m_end); + T *element_to_remove = begin_ + index; + end_--; + if (element_to_remove < end_) { + *element_to_remove = std::move(*end_); } - m_end->~T(); + end_->~T(); UPDATE_VECTOR_SIZE(this); } @@ -632,10 +632,10 @@ class Vector { BLI_assert(index < this->size()); uint last_index = this->size() - 1; for (uint i = index; i < last_index; i++) { - m_begin[i] = std::move(m_begin[i + 1]); + begin_[i] = std::move(begin_[i + 1]); } - m_begin[last_index].~T(); - m_end--; + begin_[last_index].~T(); + end_--; UPDATE_VECTOR_SIZE(this); } @@ -645,9 +645,9 @@ class Vector { */ int first_index_of_try(const T &value) const { - for (T *current = m_begin; current != m_end; current++) { + for (T *current = begin_; current != end_; current++) { if (*current == value) { - return (int)(current - m_begin); + return (int)(current - begin_); } } return -1; @@ -680,13 +680,13 @@ class Vector { const T &operator[](uint index) const { BLI_assert(index < this->size()); - return m_begin[index]; + return begin_[index]; } T &operator[](uint index) { BLI_assert(index < this->size()); - return m_begin[index]; + return begin_[index]; } /** @@ -694,7 +694,7 @@ class Vector { */ T *data() { - return m_begin; + return begin_; } /** @@ -702,25 +702,25 @@ class Vector { */ const T *data() const { - return m_begin; + return begin_; } T *begin() { - return m_begin; + return begin_; } T *end() { - return m_end; + return end_; } const T *begin() const { - return m_begin; + return begin_; } const T *end() const { - return m_end; + return end_; } /** @@ -729,7 +729,7 @@ class Vector { */ uint capacity() const { - return (uint)(m_capacity_end - m_begin); + return (uint)(capacity_end_ - begin_); } /** @@ -754,7 +754,7 @@ class Vector { std::cout << "Vector Stats: " << name << "\n"; std::cout << " Address: " << this << "\n"; std::cout << " Elements: " << this->size() << "\n"; - std::cout << " Capacity: " << (m_capacity_end - m_begin) << "\n"; + std::cout << " Capacity: " << (capacity_end_ - begin_) << "\n"; std::cout << " Inline Capacity: " << InlineBufferCapacity << "\n"; char memory_size_str[15]; @@ -765,17 +765,17 @@ class Vector { private: T *inline_buffer() const { - return (T *)m_inline_buffer.ptr(); + return (T *)inline_buffer_.ptr(); } bool is_inline() const { - return m_begin == this->inline_buffer(); + return begin_ == this->inline_buffer(); } void ensure_space_for_one() { - if (UNLIKELY(m_end >= m_capacity_end)) { + if (UNLIKELY(end_ >= capacity_end_)) { this->realloc_to_at_least(this->size() + 1); } } @@ -793,42 +793,42 @@ class Vector { uint new_capacity = std::max(min_capacity, min_new_capacity); uint size = this->size(); - T *new_array = (T *)m_allocator.allocate(new_capacity * (uint)sizeof(T), alignof(T), AT); - uninitialized_relocate_n(m_begin, size, new_array); + T *new_array = (T *)allocator_.allocate(new_capacity * (uint)sizeof(T), alignof(T), AT); + uninitialized_relocate_n(begin_, size, new_array); if (!this->is_inline()) { - m_allocator.deallocate(m_begin); + allocator_.deallocate(begin_); } - m_begin = new_array; - m_end = m_begin + size; - m_capacity_end = m_begin + new_capacity; + begin_ = new_array; + end_ = begin_ + size; + capacity_end_ = begin_ + new_capacity; } /** - * Initialize all properties, except for m_allocator, which has to be initialized beforehand. + * Initialize all properties, except for allocator_, which has to be initialized beforehand. */ template<uint OtherInlineBufferCapacity> void init_copy_from_other_vector(const Vector<T, OtherInlineBufferCapacity, Allocator> &other) { - m_allocator = other.m_allocator; + allocator_ = other.allocator_; uint size = other.size(); uint capacity = size; if (size <= InlineBufferCapacity) { - m_begin = this->inline_buffer(); + begin_ = this->inline_buffer(); capacity = InlineBufferCapacity; } else { - m_begin = (T *)m_allocator.allocate(sizeof(T) * size, alignof(T), AT); + begin_ = (T *)allocator_.allocate(sizeof(T) * size, alignof(T), AT); capacity = size; } - m_end = m_begin + size; - m_capacity_end = m_begin + capacity; + end_ = begin_ + size; + capacity_end_ = begin_ + capacity; - uninitialized_copy_n(other.data(), size, m_begin); + uninitialized_copy_n(other.data(), size, begin_); UPDATE_VECTOR_SIZE(this); } }; diff --git a/source/blender/blenlib/BLI_vector_set.hh b/source/blender/blenlib/BLI_vector_set.hh index 03f25a68cd8..6d7fd101b65 100644 --- a/source/blender/blenlib/BLI_vector_set.hh +++ b/source/blender/blenlib/BLI_vector_set.hh @@ -106,30 +106,30 @@ class VectorSet { * Slots are either empty, occupied or removed. The number of occupied slots can be computed by * subtracting the removed slots from the occupied-and-removed slots. */ - uint32_t m_removed_slots; - uint32_t m_occupied_and_removed_slots; + uint32_t removed_slots_; + uint32_t occupied_and_removed_slots_; /** * The maximum number of slots that can be used (either occupied or removed) until the set has to * grow. This is the total number of slots times the max load factor. */ - uint32_t m_usable_slots; + uint32_t usable_slots_; /** * The number of slots minus one. This is a bit mask that can be used to turn any integer into a * valid slot index efficiently. */ - uint32_t m_slot_mask; + uint32_t slot_mask_; /** This is called to hash incoming keys. */ - Hash m_hash; + Hash hash_; /** This is called to check equality of two keys. */ - IsEqual m_is_equal; + IsEqual is_equal_; /** The max load factor is 1/2 = 50% by default. */ #define LOAD_FACTOR 1, 2 - LoadFactor m_max_load_factor = LoadFactor(LOAD_FACTOR); + LoadFactor max_load_factor_ = LoadFactor(LOAD_FACTOR); using SlotArray = Array<Slot, LoadFactor::compute_total_slots(4, LOAD_FACTOR), Allocator>; #undef LOAD_FACTOR @@ -137,19 +137,19 @@ class VectorSet { * This is the array that contains the actual slots. There is always at least one empty slot and * the size of the array is a power of two. */ - SlotArray m_slots; + SlotArray slots_; /** * Pointer to an array that contains all keys. The keys are sorted by insertion order as long as * no keys are removed. The first set->size() elements in this array are initialized. The - * capacity of the array is m_usable_slots. + * capacity of the array is usable_slots_. */ - Key *m_keys; + Key *keys_; /** Iterate over a slot index sequence for a given hash. */ #define VECTOR_SET_SLOT_PROBING_BEGIN(HASH, R_SLOT) \ - SLOT_PROBING_BEGIN (ProbingStrategy, HASH, m_slot_mask, SLOT_INDEX) \ - auto &R_SLOT = m_slots[SLOT_INDEX]; + SLOT_PROBING_BEGIN (ProbingStrategy, HASH, slot_mask_, SLOT_INDEX) \ + auto &R_SLOT = slots_[SLOT_INDEX]; #define VECTOR_SET_SLOT_PROBING_END() SLOT_PROBING_END() public: @@ -159,12 +159,12 @@ class VectorSet { * is performed on the first insertion. */ VectorSet() - : m_removed_slots(0), - m_occupied_and_removed_slots(0), - m_usable_slots(0), - m_slot_mask(0), - m_slots(1), - m_keys(nullptr) + : removed_slots_(0), + occupied_and_removed_slots_(0), + usable_slots_(0), + slot_mask_(0), + slots_(1), + keys_(nullptr) { } @@ -178,37 +178,37 @@ class VectorSet { ~VectorSet() { - destruct_n(m_keys, this->size()); - if (m_keys != nullptr) { - this->deallocate_keys_array(m_keys); + destruct_n(keys_, this->size()); + if (keys_ != nullptr) { + this->deallocate_keys_array(keys_); } } VectorSet(const VectorSet &other) - : m_removed_slots(other.m_removed_slots), - m_occupied_and_removed_slots(other.m_occupied_and_removed_slots), - m_usable_slots(other.m_usable_slots), - m_slot_mask(other.m_slot_mask), - m_slots(other.m_slots) + : removed_slots_(other.removed_slots_), + occupied_and_removed_slots_(other.occupied_and_removed_slots_), + usable_slots_(other.usable_slots_), + slot_mask_(other.slot_mask_), + slots_(other.slots_) { - m_keys = this->allocate_keys_array(m_usable_slots); - uninitialized_copy_n(other.m_keys, other.size(), m_keys); + keys_ = this->allocate_keys_array(usable_slots_); + uninitialized_copy_n(other.keys_, other.size(), keys_); } VectorSet(VectorSet &&other) noexcept - : m_removed_slots(other.m_removed_slots), - m_occupied_and_removed_slots(other.m_occupied_and_removed_slots), - m_usable_slots(other.m_usable_slots), - m_slot_mask(other.m_slot_mask), - m_slots(std::move(other.m_slots)), - m_keys(other.m_keys) + : removed_slots_(other.removed_slots_), + occupied_and_removed_slots_(other.occupied_and_removed_slots_), + usable_slots_(other.usable_slots_), + slot_mask_(other.slot_mask_), + slots_(std::move(other.slots_)), + keys_(other.keys_) { - other.m_removed_slots = 0; - other.m_occupied_and_removed_slots = 0; - other.m_usable_slots = 0; - other.m_slot_mask = 0; - other.m_slots = SlotArray(1); - other.m_keys = nullptr; + other.removed_slots_ = 0; + other.occupied_and_removed_slots_ = 0; + other.usable_slots_ = 0; + other.slot_mask_ = 0; + other.slots_ = SlotArray(1); + other.keys_ = nullptr; } VectorSet &operator=(const VectorSet &other) @@ -242,11 +242,11 @@ class VectorSet { */ void add_new(const Key &key) { - this->add_new__impl(key, m_hash(key)); + this->add_new__impl(key, hash_(key)); } void add_new(Key &&key) { - this->add_new__impl(std::move(key), m_hash(key)); + this->add_new__impl(std::move(key), hash_(key)); } /** @@ -269,7 +269,7 @@ class VectorSet { */ template<typename ForwardKey> bool add_as(ForwardKey &&key) { - return this->add__impl(std::forward<ForwardKey>(key), m_hash(key)); + return this->add__impl(std::forward<ForwardKey>(key), hash_(key)); } /** @@ -301,7 +301,7 @@ class VectorSet { */ template<typename ForwardKey> bool contains_as(const ForwardKey &key) const { - return this->contains__impl(key, m_hash(key)); + return this->contains__impl(key, hash_(key)); } /** @@ -320,7 +320,7 @@ class VectorSet { */ template<typename ForwardKey> bool remove_as(const ForwardKey &key) { - return this->remove__impl(key, m_hash(key)); + return this->remove__impl(key, hash_(key)); } /** @@ -338,7 +338,7 @@ class VectorSet { */ template<typename ForwardKey> void remove_contained_as(const ForwardKey &key) { - this->remove_contained__impl(key, m_hash(key)); + this->remove_contained__impl(key, hash_(key)); } /** @@ -364,7 +364,7 @@ class VectorSet { */ template<typename ForwardKey> uint32_t index_of_as(const ForwardKey &key) const { - return this->index_of__impl(key, m_hash(key)); + return this->index_of__impl(key, hash_(key)); } /** @@ -381,7 +381,7 @@ class VectorSet { */ template<typename ForwardKey> int32_t index_of_try_as(const ForwardKey &key) const { - return this->index_of_try__impl(key, m_hash(key)); + return this->index_of_try__impl(key, hash_(key)); } /** @@ -389,17 +389,17 @@ class VectorSet { */ const Key *data() const { - return m_keys; + return keys_; } const Key *begin() const { - return m_keys; + return keys_; } const Key *end() const { - return m_keys + this->size(); + return keys_ + this->size(); } /** @@ -408,12 +408,12 @@ class VectorSet { const Key &operator[](uint32_t index) const { BLI_assert(index <= this->size()); - return m_keys[index]; + return keys_[index]; } operator Span<Key>() const { - return Span<Key>(m_keys, this->size()); + return Span<Key>(keys_, this->size()); } /** @@ -441,7 +441,7 @@ class VectorSet { */ uint32_t size() const { - return m_occupied_and_removed_slots - m_removed_slots; + return occupied_and_removed_slots_ - removed_slots_; } /** @@ -449,7 +449,7 @@ class VectorSet { */ bool is_empty() const { - return m_occupied_and_removed_slots == m_removed_slots; + return occupied_and_removed_slots_ == removed_slots_; } /** @@ -457,7 +457,7 @@ class VectorSet { */ uint32_t capacity() const { - return m_slots.size(); + return slots_.size(); } /** @@ -465,7 +465,7 @@ class VectorSet { */ uint32_t removed_amount() const { - return m_removed_slots; + return removed_slots_; } /** @@ -482,7 +482,7 @@ class VectorSet { */ uint32_t size_in_bytes() const { - return (uint32_t)(sizeof(Slot) * m_slots.size() + sizeof(Key) * m_usable_slots); + return (uint32_t)(sizeof(Slot) * slots_.size() + sizeof(Key) * usable_slots_); } /** @@ -490,7 +490,7 @@ class VectorSet { */ void reserve(uint32_t n) { - if (m_usable_slots < n) { + if (usable_slots_ < n) { this->realloc_and_reinsert(n); } } @@ -501,57 +501,57 @@ class VectorSet { */ uint32_t count_collisions(const Key &key) const { - return this->count_collisions__impl(key, m_hash(key)); + return this->count_collisions__impl(key, hash_(key)); } private: BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots) { uint32_t total_slots, usable_slots; - m_max_load_factor.compute_total_and_usable_slots( + max_load_factor_.compute_total_and_usable_slots( SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots); uint32_t new_slot_mask = total_slots - 1; /* Optimize the case when the set was empty beforehand. We can avoid some copies here. */ if (this->size() == 0) { - m_slots.~Array(); - new (&m_slots) SlotArray(total_slots); - m_removed_slots = 0; - m_occupied_and_removed_slots = 0; - m_usable_slots = usable_slots; - m_slot_mask = new_slot_mask; - m_keys = this->allocate_keys_array(usable_slots); + slots_.~Array(); + new (&slots_) SlotArray(total_slots); + removed_slots_ = 0; + occupied_and_removed_slots_ = 0; + usable_slots_ = usable_slots; + slot_mask_ = new_slot_mask; + keys_ = this->allocate_keys_array(usable_slots); return; } SlotArray new_slots(total_slots); - for (Slot &slot : m_slots) { + for (Slot &slot : slots_) { if (slot.is_occupied()) { this->add_after_grow_and_destruct_old(slot, new_slots, new_slot_mask); } } Key *new_keys = this->allocate_keys_array(usable_slots); - uninitialized_relocate_n(m_keys, this->size(), new_keys); - this->deallocate_keys_array(m_keys); + uninitialized_relocate_n(keys_, this->size(), new_keys); + this->deallocate_keys_array(keys_); /* All occupied slots have been destructed already and empty/removed slots are assumed to be * trivially destructible. */ - m_slots.clear_without_destruct(); - m_slots = std::move(new_slots); - m_keys = new_keys; - m_occupied_and_removed_slots -= m_removed_slots; - m_usable_slots = usable_slots; - m_removed_slots = 0; - m_slot_mask = new_slot_mask; + slots_.clear_without_destruct(); + slots_ = std::move(new_slots); + keys_ = new_keys; + occupied_and_removed_slots_ -= removed_slots_; + usable_slots_ = usable_slots; + removed_slots_ = 0; + slot_mask_ = new_slot_mask; } void add_after_grow_and_destruct_old(Slot &old_slot, SlotArray &new_slots, uint32_t new_slot_mask) { - const Key &key = m_keys[old_slot.index()]; + const Key &key = keys_[old_slot.index()]; uint32_t hash = old_slot.get_hash(key, Hash()); SLOT_PROBING_BEGIN (ProbingStrategy, hash, new_slot_mask, slot_index) { @@ -570,7 +570,7 @@ class VectorSet { if (slot.is_empty()) { return false; } - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { return true; } } @@ -586,9 +586,9 @@ class VectorSet { VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { uint32_t index = this->size(); - new (m_keys + index) Key(std::forward<ForwardKey>(key)); + new (keys_ + index) Key(std::forward<ForwardKey>(key)); slot.occupy(index, hash); - m_occupied_and_removed_slots++; + occupied_and_removed_slots_++; return; } } @@ -602,12 +602,12 @@ class VectorSet { VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.is_empty()) { uint32_t index = this->size(); - new (m_keys + index) Key(std::forward<ForwardKey>(key)); - m_occupied_and_removed_slots++; + new (keys_ + index) Key(std::forward<ForwardKey>(key)); + occupied_and_removed_slots_++; slot.occupy(index, hash); return true; } - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { return false; } } @@ -619,7 +619,7 @@ class VectorSet { BLI_assert(this->contains_as(key)); VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { return slot.index(); } } @@ -630,7 +630,7 @@ class VectorSet { int32_t index_of_try__impl(const ForwardKey &key, uint32_t hash) const { VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { return (int32_t)slot.index(); } if (slot.is_empty()) { @@ -645,11 +645,11 @@ class VectorSet { BLI_assert(this->size() > 0); uint32_t index_to_pop = this->size() - 1; - Key key = std::move(m_keys[index_to_pop]); - m_keys[index_to_pop].~Key(); - uint32_t hash = m_hash(key); + Key key = std::move(keys_[index_to_pop]); + keys_[index_to_pop].~Key(); + uint32_t hash = hash_(key); - m_removed_slots++; + removed_slots_++; VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.has_index(index_to_pop)) { @@ -663,7 +663,7 @@ class VectorSet { template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash) { VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { this->remove_key_internal(slot); return true; } @@ -679,7 +679,7 @@ class VectorSet { BLI_assert(this->contains_as(key)); VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { this->remove_key_internal(slot); return; } @@ -694,19 +694,19 @@ class VectorSet { uint32_t last_element_index = size - 1; if (index_to_remove < last_element_index) { - m_keys[index_to_remove] = std::move(m_keys[last_element_index]); - this->update_slot_index(m_keys[index_to_remove], last_element_index, index_to_remove); + keys_[index_to_remove] = std::move(keys_[last_element_index]); + this->update_slot_index(keys_[index_to_remove], last_element_index, index_to_remove); } - m_keys[last_element_index].~Key(); + keys_[last_element_index].~Key(); slot.remove(); - m_removed_slots++; + removed_slots_++; return; } void update_slot_index(const Key &key, uint32_t old_index, uint32_t new_index) { - uint32_t hash = m_hash(key); + uint32_t hash = hash_(key); VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { if (slot.has_index(old_index)) { slot.update_index(new_index); @@ -722,7 +722,7 @@ class VectorSet { uint32_t collisions = 0; VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) { - if (slot.contains(key, m_is_equal, hash, m_keys)) { + if (slot.contains(key, is_equal_, hash, keys_)) { return collisions; } if (slot.is_empty()) { @@ -735,20 +735,20 @@ class VectorSet { void ensure_can_add() { - if (m_occupied_and_removed_slots >= m_usable_slots) { + if (occupied_and_removed_slots_ >= usable_slots_) { this->realloc_and_reinsert(this->size() + 1); - BLI_assert(m_occupied_and_removed_slots < m_usable_slots); + BLI_assert(occupied_and_removed_slots_ < usable_slots_); } } Key *allocate_keys_array(uint32_t size) { - return (Key *)m_slots.allocator().allocate((uint32_t)sizeof(Key) * size, alignof(Key), AT); + return (Key *)slots_.allocator().allocate((uint32_t)sizeof(Key) * size, alignof(Key), AT); } void deallocate_keys_array(Key *keys) { - m_slots.allocator().deallocate(keys); + slots_.allocator().deallocate(keys); } }; diff --git a/source/blender/blenlib/BLI_vector_set_slots.hh b/source/blender/blenlib/BLI_vector_set_slots.hh index 25148866b6c..e43b892b3f7 100644 --- a/source/blender/blenlib/BLI_vector_set_slots.hh +++ b/source/blender/blenlib/BLI_vector_set_slots.hh @@ -53,7 +53,7 @@ template<typename Key> class SimpleVectorSetSlot { /** * After the default constructor has run, the slot has to be in the empty state. */ - int32_t m_state = s_is_empty; + int32_t state_ = s_is_empty; public: /** @@ -61,7 +61,7 @@ template<typename Key> class SimpleVectorSetSlot { */ bool is_occupied() const { - return m_state >= 0; + return state_ >= 0; } /** @@ -69,7 +69,7 @@ template<typename Key> class SimpleVectorSetSlot { */ bool is_empty() const { - return m_state == s_is_empty; + return state_ == s_is_empty; } /** @@ -78,7 +78,7 @@ template<typename Key> class SimpleVectorSetSlot { uint32_t index() const { BLI_assert(this->is_occupied()); - return (uint32_t)m_state; + return (uint32_t)state_; } /** @@ -91,8 +91,8 @@ template<typename Key> class SimpleVectorSetSlot { uint32_t UNUSED(hash), const Key *keys) const { - if (m_state >= 0) { - return is_equal(key, keys[m_state]); + if (state_ >= 0) { + return is_equal(key, keys[state_]); } return false; } @@ -106,7 +106,7 @@ template<typename Key> class SimpleVectorSetSlot { { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); - m_state = other.m_state; + state_ = other.state_; } /** @@ -116,7 +116,7 @@ template<typename Key> class SimpleVectorSetSlot { void occupy(uint32_t index, uint32_t UNUSED(hash)) { BLI_assert(!this->is_occupied()); - m_state = (int32_t)index; + state_ = (int32_t)index; } /** @@ -126,7 +126,7 @@ template<typename Key> class SimpleVectorSetSlot { void update_index(uint32_t index) { BLI_assert(this->is_occupied()); - m_state = (int32_t)index; + state_ = (int32_t)index; } /** @@ -135,7 +135,7 @@ template<typename Key> class SimpleVectorSetSlot { void remove() { BLI_assert(this->is_occupied()); - m_state = s_is_removed; + state_ = s_is_removed; } /** @@ -143,7 +143,7 @@ template<typename Key> class SimpleVectorSetSlot { */ bool has_index(uint32_t index) const { - return (uint32_t)m_state == index; + return (uint32_t)state_ == index; } /** diff --git a/source/blender/blenlib/intern/BLI_index_range.cc b/source/blender/blenlib/intern/BLI_index_range.cc index 910e418a29b..9fa19143f91 100644 --- a/source/blender/blenlib/intern/BLI_index_range.cc +++ b/source/blender/blenlib/intern/BLI_index_range.cc @@ -31,16 +31,16 @@ static std::mutex current_array_mutex; Span<uint> IndexRange::as_span() const { - uint min_required_size = m_start + m_size; + uint min_required_size = start_ + size_; if (min_required_size <= current_array_size) { - return Span<uint>(current_array + m_start, m_size); + return Span<uint>(current_array + start_, size_); } std::lock_guard<std::mutex> lock(current_array_mutex); if (min_required_size <= current_array_size) { - return Span<uint>(current_array + m_start, m_size); + return Span<uint>(current_array + start_, size_); } uint new_size = std::max<uint>(1000, power_of_2_max_u(min_required_size)); @@ -54,7 +54,7 @@ Span<uint> IndexRange::as_span() const std::atomic_thread_fence(std::memory_order_seq_cst); current_array_size = new_size; - return Span<uint>(current_array + m_start, m_size); + return Span<uint>(current_array + start_, size_); } } // namespace blender diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc index ff39265d681..5c02ab977b8 100644 --- a/source/blender/blenlib/intern/dot_export.cc +++ b/source/blender/blenlib/intern/dot_export.cc @@ -27,8 +27,8 @@ namespace dot { Node &Graph::new_node(StringRef label) { Node *node = new Node(*this); - m_nodes.append(std::unique_ptr<Node>(node)); - m_top_level_nodes.add_new(node); + nodes_.append(std::unique_ptr<Node>(node)); + top_level_nodes_.add_new(node); node->set_attribute("label", label); return *node; } @@ -36,8 +36,8 @@ Node &Graph::new_node(StringRef label) Cluster &Graph::new_cluster(StringRef label) { Cluster *cluster = new Cluster(*this); - m_clusters.append(std::unique_ptr<Cluster>(cluster)); - m_top_level_clusters.add_new(cluster); + clusters_.append(std::unique_ptr<Cluster>(cluster)); + top_level_clusters_.add_new(cluster); cluster->set_attribute("label", label); return *cluster; } @@ -45,55 +45,55 @@ Cluster &Graph::new_cluster(StringRef label) UndirectedEdge &UndirectedGraph::new_edge(NodePort a, NodePort b) { UndirectedEdge *edge = new UndirectedEdge(a, b); - m_edges.append(std::unique_ptr<UndirectedEdge>(edge)); + edges_.append(std::unique_ptr<UndirectedEdge>(edge)); return *edge; } DirectedEdge &DirectedGraph::new_edge(NodePort from, NodePort to) { DirectedEdge *edge = new DirectedEdge(from, to); - m_edges.append(std::unique_ptr<DirectedEdge>(edge)); + edges_.append(std::unique_ptr<DirectedEdge>(edge)); return *edge; } void Cluster::set_parent_cluster(Cluster *new_parent) { - if (m_parent == new_parent) { + if (parent_ == new_parent) { return; } - else if (m_parent == nullptr) { - m_graph.m_top_level_clusters.remove(this); - new_parent->m_children.add_new(this); + else if (parent_ == nullptr) { + graph_.top_level_clusters_.remove(this); + new_parent->children_.add_new(this); } else if (new_parent == nullptr) { - m_parent->m_children.remove(this); - m_graph.m_top_level_clusters.add_new(this); + parent_->children_.remove(this); + graph_.top_level_clusters_.add_new(this); } else { - m_parent->m_children.remove(this); - new_parent->m_children.add_new(this); + parent_->children_.remove(this); + new_parent->children_.add_new(this); } - m_parent = new_parent; + parent_ = new_parent; } void Node::set_parent_cluster(Cluster *cluster) { - if (m_cluster == cluster) { + if (cluster_ == cluster) { return; } - else if (m_cluster == nullptr) { - m_graph.m_top_level_nodes.remove(this); - cluster->m_nodes.add_new(this); + else if (cluster_ == nullptr) { + graph_.top_level_nodes_.remove(this); + cluster->nodes_.add_new(this); } else if (cluster == nullptr) { - m_cluster->m_nodes.remove(this); - m_graph.m_top_level_nodes.add_new(this); + cluster_->nodes_.remove(this); + graph_.top_level_nodes_.add_new(this); } else { - m_cluster->m_nodes.remove(this); - cluster->m_nodes.add_new(this); + cluster_->nodes_.remove(this); + cluster->nodes_.add_new(this); } - m_cluster = cluster; + cluster_ = cluster; } /* Utility methods @@ -101,7 +101,7 @@ void Node::set_parent_cluster(Cluster *cluster) void Graph::set_random_cluster_bgcolors() { - for (Cluster *cluster : m_top_level_clusters) { + for (Cluster *cluster : top_level_clusters_) { cluster->set_random_cluster_bgcolors(); } } @@ -113,7 +113,7 @@ void Cluster::set_random_cluster_bgcolors() float value = 0.8f; this->set_attribute("bgcolor", color_attr_from_hsv(hue, staturation, value)); - for (Cluster *cluster : m_children) { + for (Cluster *cluster : children_) { cluster->set_random_cluster_bgcolors(); } } @@ -128,7 +128,7 @@ std::string DirectedGraph::to_dot_string() const this->export__declare_nodes_and_clusters(ss); ss << "\n"; - for (const std::unique_ptr<DirectedEdge> &edge : m_edges) { + for (const std::unique_ptr<DirectedEdge> &edge : edges_) { edge->export__as_edge_statement(ss); ss << "\n"; } @@ -144,7 +144,7 @@ std::string UndirectedGraph::to_dot_string() const this->export__declare_nodes_and_clusters(ss); ss << "\n"; - for (const std::unique_ptr<UndirectedEdge> &edge : m_edges) { + for (const std::unique_ptr<UndirectedEdge> &edge : edges_) { edge->export__as_edge_statement(ss); ss << "\n"; } @@ -156,14 +156,14 @@ std::string UndirectedGraph::to_dot_string() const void Graph::export__declare_nodes_and_clusters(std::stringstream &ss) const { ss << "graph "; - m_attributes.export__as_bracket_list(ss); + attributes_.export__as_bracket_list(ss); ss << "\n\n"; - for (Node *node : m_top_level_nodes) { + for (Node *node : top_level_nodes_) { node->export__as_declaration(ss); } - for (Cluster *cluster : m_top_level_clusters) { + for (Cluster *cluster : top_level_clusters_) { cluster->export__declare_nodes_and_clusters(ss); } } @@ -173,14 +173,14 @@ void Cluster::export__declare_nodes_and_clusters(std::stringstream &ss) const ss << "subgraph cluster_" << (uintptr_t)this << " {\n"; ss << "graph "; - m_attributes.export__as_bracket_list(ss); + attributes_.export__as_bracket_list(ss); ss << "\n\n"; - for (Node *node : m_nodes) { + for (Node *node : nodes_) { node->export__as_declaration(ss); } - for (Cluster *cluster : m_children) { + for (Cluster *cluster : children_) { cluster->export__declare_nodes_and_clusters(ss); } @@ -189,26 +189,26 @@ void Cluster::export__declare_nodes_and_clusters(std::stringstream &ss) const void DirectedEdge::export__as_edge_statement(std::stringstream &ss) const { - m_a.to_dot_string(ss); + a_.to_dot_string(ss); ss << " -> "; - m_b.to_dot_string(ss); + b_.to_dot_string(ss); ss << " "; - m_attributes.export__as_bracket_list(ss); + attributes_.export__as_bracket_list(ss); } void UndirectedEdge::export__as_edge_statement(std::stringstream &ss) const { - m_a.to_dot_string(ss); + a_.to_dot_string(ss); ss << " -- "; - m_b.to_dot_string(ss); + b_.to_dot_string(ss); ss << " "; - m_attributes.export__as_bracket_list(ss); + attributes_.export__as_bracket_list(ss); } void AttributeList::export__as_bracket_list(std::stringstream &ss) const { ss << "["; - m_attributes.foreach_item([&](StringRef key, StringRef value) { + attributes_.foreach_item([&](StringRef key, StringRef value) { if (StringRef(value).startswith("<")) { /* Don't draw the quotes, this is an html-like value. */ ss << key << "=" << value << ", "; @@ -229,15 +229,15 @@ void Node::export__as_declaration(std::stringstream &ss) const { this->export__as_id(ss); ss << " "; - m_attributes.export__as_bracket_list(ss); + attributes_.export__as_bracket_list(ss); ss << "\n"; } void NodePort::to_dot_string(std::stringstream &ss) const { - m_node->export__as_id(ss); - if (m_port_name.has_value()) { - ss << ":" << *m_port_name; + node_->export__as_id(ss); + if (port_name_.has_value()) { + ss << ":" << *port_name_; } } @@ -252,7 +252,7 @@ NodeWithSocketsRef::NodeWithSocketsRef(Node &node, StringRef name, Span<std::string> input_names, Span<std::string> output_names) - : m_node(&node) + : node_(&node) { std::stringstream ss; @@ -297,8 +297,8 @@ NodeWithSocketsRef::NodeWithSocketsRef(Node &node, ss << "</table>>"; - m_node->set_attribute("label", ss.str()); - m_node->set_shape(Attr_shape::Rectangle); + node_->set_attribute("label", ss.str()); + node_->set_shape(Attr_shape::Rectangle); } } // namespace dot |