everywhere: Don't assume sstring::begin() and sstring::end() are pointers

If we switch to using std::string we have to handle begin and end
returning iterators.

Signed-off-by: Rafael Ávila de Espíndola <espindola@scylladb.com>
This commit is contained in:
Rafael Ávila de Espíndola
2020-03-05 11:20:46 -08:00
parent 0cb7182768
commit caef2ef903
9 changed files with 15 additions and 15 deletions

View File

@@ -338,7 +338,7 @@ column_condition::raw::prepare(database& db, const sstring& keyspace, const colu
const sstring& pattern = literal_term->get_raw_text();
return column_condition::condition(receiver, collection_element_term,
_value->prepare(db, keyspace, value_spec),
std::make_unique<like_matcher>(bytes_view(reinterpret_cast<const int8_t*>(pattern.begin()), pattern.size())),
std::make_unique<like_matcher>(bytes_view(reinterpret_cast<const int8_t*>(pattern.data()), pattern.size())),
_op);
} else {
// Pass through rhs value, matcher object built on execution

View File

@@ -99,7 +99,7 @@ public:
: _code(code)
, _msg(std::move(msg))
{ }
virtual const char* what() const noexcept override { return _msg.begin(); }
virtual const char* what() const noexcept override { return _msg.c_str(); }
exception_code code() const { return _code; }
sstring get_message() const { return what(); }
};

View File

@@ -71,7 +71,7 @@ inline Json::Value to_json_value(const sstring& raw) {
#if defined(JSONCPP_VERSION_HEXA) && (JSONCPP_VERSION_HEXA >= 0x010400) // >= 1.4.0
Json::CharReaderBuilder rbuilder;
std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
bool result = reader->parse(raw.begin(), raw.end(), &root, NULL);
bool result = reader->parse(raw.data(), raw.data() + raw.size(), &root, NULL);
if (!result) {
throw std::runtime_error(format("Failed to parse JSON: {}", raw));
}
@@ -86,7 +86,7 @@ inline bool to_json_value(const sstring& raw, Json::Value& root) {
#if defined(JSONCPP_VERSION_HEXA) && (JSONCPP_VERSION_HEXA >= 0x010400) // >= 1.4.0
Json::CharReaderBuilder rbuilder;
std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
return reader->parse(raw.begin(), raw.end(), &root, NULL);
return reader->parse(raw.data(), raw.data() + raw.size(), &root, NULL);
#else
Json::Reader reader;
return reader.parse(std::string{raw}, root);

View File

@@ -28,7 +28,7 @@ class redis_exception : public std::exception {
sstring _message;
public:
redis_exception(sstring message) : _message(std::move(message)) {}
virtual const char* what() const noexcept override { return _message.begin(); }
virtual const char* what() const noexcept override { return _message.c_str(); }
const sstring& what_message() const noexcept { return _message; }
};

View File

@@ -573,13 +573,13 @@ struct serializer<sstring> {
static sstring read(Input& in) {
auto sz = deserialize(in, boost::type<uint32_t>());
sstring v(sstring::initialized_later(), sz);
in.read(v.begin(), sz);
in.read(v.data(), sz);
return v;
}
template<typename Output>
static void write(Output& out, const sstring& v) {
safe_serialize_as_uint32(out, uint32_t(v.size()));
out.write(v.begin(), v.size());
out.write(v.data(), v.size());
}
template<typename Input>
static void skip(Input& in) {
@@ -712,7 +712,7 @@ unknown_variant_type deserialize(Input& in, boost::type<unknown_variant_type>) {
auto index = deserialize(in, boost::type<size_type>());
auto sz = size - sizeof(size_type) * 2;
sstring v(sstring::initialized_later(), sz);
in.read(v.begin(), sz);
in.read(v.data(), sz);
return unknown_variant_type{ index, std::move(v) };
});
}

View File

@@ -65,12 +65,12 @@ void test() {
for (auto size : {0, 1, 2, 10, 13, 16, 17, 22, 31, 1024, 2000, 80000}) {
auto data = make_random_string(size);
auto current = Impl::checksum(data.cbegin(), data.size());
auto ref_current = ReferenceImpl::checksum(data.cbegin(), data.size());
auto current = Impl::checksum(data.data(), data.size());
auto ref_current = ReferenceImpl::checksum(data.data(), data.size());
BOOST_REQUIRE_EQUAL(current, ref_current);
auto new_rolling = Impl::checksum(rolling, data.cbegin(), data.size());
auto ref_new_rolling = ReferenceImpl::checksum(rolling, data.cbegin(), data.size());
auto new_rolling = Impl::checksum(rolling, data.data(), data.size());
auto ref_new_rolling = ReferenceImpl::checksum(rolling, data.data(), data.size());
BOOST_REQUIRE_EQUAL(new_rolling, ref_new_rolling);
auto new_rolling_via_combine = Impl::checksum_combine(rolling, current, data.size());

View File

@@ -43,7 +43,7 @@
using namespace sstables;
bytes as_bytes(const sstring& s) {
return { reinterpret_cast<const int8_t*>(s.begin()), s.size() };
return { reinterpret_cast<const int8_t*>(s.data()), s.size() };
}
future<> test_using_working_sst(schema_ptr s, sstring dir, int64_t gen) {

View File

@@ -35,7 +35,7 @@ int main(int argc, char* argv[]) {
time_it([&] {
cql3_parser::CqlLexer::collector_type lexer_error_collector(query);
cql3_parser::CqlParser::collector_type parser_error_collector(query);
cql3_parser::CqlLexer::InputStreamType input{reinterpret_cast<const ANTLR_UINT8*>(query.begin()), ANTLR_ENC_UTF8, static_cast<ANTLR_UINT32>(query.size()), nullptr};
cql3_parser::CqlLexer::InputStreamType input{reinterpret_cast<const ANTLR_UINT8*>(query.data()), ANTLR_ENC_UTF8, static_cast<ANTLR_UINT32>(query.size()), nullptr};
cql3_parser::CqlLexer lexer{&input};
lexer.set_error_listener(lexer_error_collector);
cql3_parser::CqlParser::TokenStreamType tstream(ANTLR_SIZE_HINT, lexer.get_tokSource());

View File

@@ -109,7 +109,7 @@ private:
template <typename CqlFrameHeaderType>
sstring make_frame_one(uint8_t version, size_t length) {
sstring frame_buf(sstring::initialized_later(), sizeof(CqlFrameHeaderType));
auto* frame = reinterpret_cast<CqlFrameHeaderType*>(frame_buf.begin());
auto* frame = reinterpret_cast<CqlFrameHeaderType*>(frame_buf.data());
frame->version = version | 0x80;
frame->flags = _flags;
frame->opcode = static_cast<uint8_t>(_opcode);