From e9a050da78aecd53b82a29999a3fa13d635cdcd8 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 15 Jul 2015 14:04:48 +0200 Subject: [PATCH] sstables: Obtain the key from entries using get_key() rather than casting to bytes_view The entry contains not only the key, but other stuff like position. Why would casting to bytes_view give the view on just the key and not the whole entry. Better to be explicit. --- sstables/partition.cc | 5 ++--- sstables/types.hh | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sstables/partition.cc b/sstables/partition.cc index 03433fcabb..cec44244bd 100644 --- a/sstables/partition.cc +++ b/sstables/partition.cc @@ -33,7 +33,7 @@ namespace sstables { * the extra information when not needed. * * This code should work in all kinds of vectors in whose's elements is possible to aquire - * a key view. + * a key view via get_key(). */ template int sstable::binary_search(const T& entries, const key& sk, const dht::token& token) { @@ -47,8 +47,7 @@ int sstable::binary_search(const T& entries, const key& sk, const dht::token& to // creation by keeping only a key view, and then manually carrying out // both parts of the comparison ourselves. mid = low + ((high - low) >> 1); - auto mid_bytes = bytes_view(entries[mid]); - auto mid_key = key_view(mid_bytes); + key_view mid_key = entries[mid].get_key(); auto mid_token = partitioner.get_token(mid_key); if (token == mid_token) { diff --git a/sstables/types.hh b/sstables/types.hh index 74f6976e10..43242bc61a 100644 --- a/sstables/types.hh +++ b/sstables/types.hh @@ -12,6 +12,7 @@ #include "streaming_histogram.hh" #include "estimated_histogram.hh" #include "column_name_helper.hh" +#include "sstables/key.hh" #include #include #include @@ -43,8 +44,8 @@ struct index_entry { uint64_t position; disk_string promoted_index; - explicit operator bytes_view() const { - return bytes_view(key); + key_view get_key() const { + return { bytes_view(key) }; } }; @@ -52,8 +53,8 @@ struct summary_entry { bytes key; uint64_t position; - explicit operator bytes_view() const { - return key; + key_view get_key() const { + return { key }; } bool operator==(const summary_entry& x) const {