[V1][Minor] Optimize get_cached_block (#16135)

This commit is contained in:
Woosuk Kwon 2025-04-06 13:48:14 -07:00 committed by GitHub
parent 9bde5ba127
commit b10e519895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,11 +67,11 @@ class BlockPool:
Returns: Returns:
The cached block if it exists, or None. The cached block if it exists, or None.
""" """
if block_hash in self.cached_block_hash_to_block: cached_blocks = self.cached_block_hash_to_block.get(block_hash)
first_block_id = list( if not cached_blocks:
self.cached_block_hash_to_block[block_hash].keys())[0]
return self.cached_block_hash_to_block[block_hash][first_block_id]
return None return None
first_block_id = next(iter(cached_blocks))
return cached_blocks[first_block_id]
def cache_full_blocks( def cache_full_blocks(
self, self,