Simplify GlobalHandles::NodeBlock<>::From
Use pointer arithmetic to go back to the first nodes_ element instead of computing the address manually. Bug: none Change-Id: I887c41908dc6891ed15aa03698ca2305924dcab2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2512904 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Hans Wennborg <hans@chromium.org> Cr-Commit-Position: refs/heads/master@{#70913}
This commit is contained in:
parent
4c419bce7e
commit
8b0cb19ea2
@ -80,9 +80,8 @@ class GlobalHandles::NodeBlock final {
|
||||
template <class NodeType>
|
||||
const GlobalHandles::NodeBlock<NodeType>*
|
||||
GlobalHandles::NodeBlock<NodeType>::From(const NodeType* node) {
|
||||
uintptr_t ptr = reinterpret_cast<const uintptr_t>(node) -
|
||||
sizeof(NodeType) * node->index();
|
||||
const BlockType* block = reinterpret_cast<const BlockType*>(ptr);
|
||||
const NodeType* firstNode = node - node->index();
|
||||
const BlockType* block = reinterpret_cast<const BlockType*>(firstNode);
|
||||
DCHECK_EQ(node, block->at(node->index()));
|
||||
return block;
|
||||
}
|
||||
@ -90,9 +89,8 @@ GlobalHandles::NodeBlock<NodeType>::From(const NodeType* node) {
|
||||
template <class NodeType>
|
||||
GlobalHandles::NodeBlock<NodeType>* GlobalHandles::NodeBlock<NodeType>::From(
|
||||
NodeType* node) {
|
||||
uintptr_t ptr =
|
||||
reinterpret_cast<uintptr_t>(node) - sizeof(NodeType) * node->index();
|
||||
BlockType* block = reinterpret_cast<BlockType*>(ptr);
|
||||
NodeType* firstNode = node - node->index();
|
||||
BlockType* block = reinterpret_cast<BlockType*>(firstNode);
|
||||
DCHECK_EQ(node, block->at(node->index()));
|
||||
return block;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user