From 8b0cb19ea263dcc9fd933c6d68e9a3dfef00e107 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Sat, 31 Oct 2020 13:45:36 +0100 Subject: [PATCH] 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 Commit-Queue: Hans Wennborg Cr-Commit-Position: refs/heads/master@{#70913} --- src/handles/global-handles.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/handles/global-handles.cc b/src/handles/global-handles.cc index 57a2e1901f..1782514d6e 100644 --- a/src/handles/global-handles.cc +++ b/src/handles/global-handles.cc @@ -80,9 +80,8 @@ class GlobalHandles::NodeBlock final { template const GlobalHandles::NodeBlock* GlobalHandles::NodeBlock::From(const NodeType* node) { - uintptr_t ptr = reinterpret_cast(node) - - sizeof(NodeType) * node->index(); - const BlockType* block = reinterpret_cast(ptr); + const NodeType* firstNode = node - node->index(); + const BlockType* block = reinterpret_cast(firstNode); DCHECK_EQ(node, block->at(node->index())); return block; } @@ -90,9 +89,8 @@ GlobalHandles::NodeBlock::From(const NodeType* node) { template GlobalHandles::NodeBlock* GlobalHandles::NodeBlock::From( NodeType* node) { - uintptr_t ptr = - reinterpret_cast(node) - sizeof(NodeType) * node->index(); - BlockType* block = reinterpret_cast(ptr); + NodeType* firstNode = node - node->index(); + BlockType* block = reinterpret_cast(firstNode); DCHECK_EQ(node, block->at(node->index())); return block; }