Commit 8b0cb19e authored by Hans Wennborg's avatar Hans Wennborg Committed by Commit Bot

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/+/2512904Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70913}
parent 4c419bce
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment