diff options
Diffstat (limited to 'vespalib')
190 files changed, 710 insertions, 1211 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index 49e0438fec4..82b5907acfc 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -36,7 +36,6 @@ vespa_define_module( src/tests/barrier src/tests/benchmark src/tests/benchmark_timer - src/tests/bits src/tests/box src/tests/btree src/tests/btree/btree-scan-speed @@ -53,8 +52,6 @@ vespa_define_module( src/tests/coro/received src/tests/coro/waiting_for src/tests/cpu_usage - src/tests/crc - src/tests/crypto src/tests/data/databuffer src/tests/data/input_reader src/tests/data/lz4_encode_decode @@ -81,7 +78,6 @@ vespa_define_module( src/tests/drop-file-from-cache src/tests/dual_merge_director src/tests/encoding/base64 - src/tests/eventbarrier src/tests/exception_classes src/tests/execution_profiler src/tests/executor @@ -104,8 +100,6 @@ vespa_define_module( src/tests/invokeservice src/tests/io/fileutil src/tests/io/mapped_file_input - src/tests/issue - src/tests/json src/tests/latch src/tests/left_right_heap src/tests/make_fixture_macros @@ -126,7 +120,6 @@ vespa_define_module( src/tests/net/tls/policy_checking_certificate_verifier src/tests/net/tls/protocol_snooping src/tests/net/tls/transport_options - src/tests/nexus src/tests/nice src/tests/objects/identifiable src/tests/objects/nbostream @@ -139,15 +132,12 @@ vespa_define_module( src/tests/portal/handle_manager src/tests/portal/http_request src/tests/portal/reactor - src/tests/printable src/tests/priority_queue src/tests/process src/tests/programoptions src/tests/random - src/tests/ref_counted src/tests/regex src/tests/rendezvous - src/tests/require src/tests/runnable_pair src/tests/rusage src/tests/rw_spin_lock @@ -155,7 +145,6 @@ vespa_define_module( src/tests/sha1 src/tests/shared_operation_throttler src/tests/shared_string_repo - src/tests/sharedptr src/tests/shutdownguard src/tests/signalhandler src/tests/simple_thread_bundle @@ -164,7 +153,6 @@ vespa_define_module( src/tests/slime/are_equal src/tests/slime/external_data_value src/tests/slime/summary-feature-benchmark - src/tests/small_vector src/tests/spin_lock src/tests/stash src/tests/state_server @@ -194,27 +182,14 @@ vespa_define_module( src/tests/tutorial/minimal src/tests/tutorial/simple src/tests/tutorial/threads - src/tests/typify src/tests/unwind_message - src/tests/util/bfloat16 - src/tests/util/cgroup_resource_limits - src/tests/util/file_area_freelist - src/tests/util/generation_hold_list - src/tests/util/generationhandler + src/tests/util src/tests/util/generationhandler_stress src/tests/util/hamming src/tests/util/md5 - src/tests/util/memory_trap - src/tests/util/mmap_file_allocator - src/tests/util/mmap_file_allocator_factory - src/tests/util/rcuvector - src/tests/util/size_literals - src/tests/util/static_string - src/tests/util/string_escape src/tests/valgrind src/tests/visit_ranges src/tests/wakeup - src/tests/xmlserializable src/tests/zcurve LIBS diff --git a/vespalib/src/tests/bits/.gitignore b/vespalib/src/tests/bits/.gitignore deleted file mode 100644 index b5330fc2580..00000000000 --- a/vespalib/src/tests/bits/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -bits_test -vespalib_bits_test_app diff --git a/vespalib/src/tests/bits/CMakeLists.txt b/vespalib/src/tests/bits/CMakeLists.txt deleted file mode 100644 index 3ba0c6afc1c..00000000000 --- a/vespalib/src/tests/bits/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_bits_test_app TEST - SOURCES - bits_test.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_bits_test_app COMMAND vespalib_bits_test_app) diff --git a/vespalib/src/tests/crc/.gitignore b/vespalib/src/tests/crc/.gitignore deleted file mode 100644 index cd64c20e0a4..00000000000 --- a/vespalib/src/tests/crc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -crc_test -vespalib_crc_test_app diff --git a/vespalib/src/tests/crc/CMakeLists.txt b/vespalib/src/tests/crc/CMakeLists.txt deleted file mode 100644 index a7de5d1fa7a..00000000000 --- a/vespalib/src/tests/crc/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_crc_test_app TEST - SOURCES - crc_test.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_crc_test_app COMMAND vespalib_crc_test_app boost) diff --git a/vespalib/src/tests/crypto/CMakeLists.txt b/vespalib/src/tests/crypto/CMakeLists.txt deleted file mode 100644 index 0da9b6db1f0..00000000000 --- a/vespalib/src/tests/crypto/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_crypto_crypto_test_app TEST - SOURCES - crypto_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_crypto_crypto_test_app COMMAND vespalib_crypto_crypto_test_app) - diff --git a/vespalib/src/tests/eventbarrier/.gitignore b/vespalib/src/tests/eventbarrier/.gitignore deleted file mode 100644 index 89007477b2a..00000000000 --- a/vespalib/src/tests/eventbarrier/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -eventbarrier_test -vespalib_eventbarrier_test_app diff --git a/vespalib/src/tests/eventbarrier/CMakeLists.txt b/vespalib/src/tests/eventbarrier/CMakeLists.txt deleted file mode 100644 index e4ee14a1ed7..00000000000 --- a/vespalib/src/tests/eventbarrier/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_eventbarrier_test_app TEST - SOURCES - eventbarrier.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_eventbarrier_test_app COMMAND vespalib_eventbarrier_test_app) diff --git a/vespalib/src/tests/execution_profiler/execution_profiler_test.cpp b/vespalib/src/tests/execution_profiler/execution_profiler_test.cpp index 9c31e2dd46a..dd7ba04b281 100644 --- a/vespalib/src/tests/execution_profiler/execution_profiler_test.cpp +++ b/vespalib/src/tests/execution_profiler/execution_profiler_test.cpp @@ -228,7 +228,7 @@ TEST(ExecutionProfilerTest, flat_profiling_does_not_report_tasks_with_count_0) { EXPECT_EQ(slime["profiler"].asString().make_string(), "flat"); EXPECT_EQ(slime["topn"].asLong(), 2); EXPECT_EQ(slime["roots"].entries(), 1); - EXPECT_EQ(slime["roots"][0]["name"].asString().make_stringref(), "baz"); + EXPECT_EQ(slime["roots"][0]["name"].asString().make_stringview(), "baz"); EXPECT_EQ(slime["roots"][0]["count"].asLong(), 1); } diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp index 51b755e1668..a1831c8e415 100644 --- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp +++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp @@ -211,7 +211,7 @@ TEST("require that vespalib::dirname works") TEST("require that vespalib::getOpenErrorString works") { - stringref dirName = "mydir"; + std::string_view dirName = "mydir"; std::filesystem::remove_all(std::filesystem::path(dirName)); std::filesystem::create_directory(std::filesystem::path(dirName)); { diff --git a/vespalib/src/tests/json/.gitignore b/vespalib/src/tests/json/.gitignore deleted file mode 100644 index 9918fbce6e8..00000000000 --- a/vespalib/src/tests/json/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vespalib_json_test_app diff --git a/vespalib/src/tests/json/CMakeLists.txt b/vespalib/src/tests/json/CMakeLists.txt deleted file mode 100644 index 89471e18d74..00000000000 --- a/vespalib/src/tests/json/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_json_test_app TEST - SOURCES - json.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_json_test_app COMMAND vespalib_json_test_app boost) diff --git a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp index ed20dd6bcf4..937891fb1e4 100644 --- a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp +++ b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp @@ -85,7 +85,7 @@ PhL9XBnJJfzvG5GKXIK/iZgFuYkCIFLp+SIQ5Nc1+NzrU2ii/mkzCgC4N/nOWu9H 88OP2wnm -----END CERTIFICATE-----)"; -void write_file(vespalib::stringref path, vespalib::stringref data) { +void write_file(std::string_view path, std::string_view data) { File f(path); f.open(File::CREATE | File::TRUNC); f.write(data.data(), data.size(), 0); diff --git a/vespalib/src/tests/net/tls/direct_buffer_bio/direct_buffer_bio_test.cpp b/vespalib/src/tests/net/tls/direct_buffer_bio/direct_buffer_bio_test.cpp index c70470f95dd..b87db151e82 100644 --- a/vespalib/src/tests/net/tls/direct_buffer_bio/direct_buffer_bio_test.cpp +++ b/vespalib/src/tests/net/tls/direct_buffer_bio/direct_buffer_bio_test.cpp @@ -43,7 +43,7 @@ TEST_F("Mutable BIO_write writes to associated buffer", Fixture) { vespalib::string to_write = "hello world!"; int ret = ::BIO_write(f.mutable_bio.get(), to_write.data(), static_cast<int>(to_write.size())); EXPECT_EQUAL(static_cast<int>(to_write.size()), ret); - EXPECT_EQUAL(to_write, vespalib::stringref(f.tmp_buf.data(), to_write.size())); + EXPECT_EQUAL(to_write, std::string_view(f.tmp_buf.data(), to_write.size())); EXPECT_EQUAL(static_cast<int>(to_write.size()), BIO_pending(f.mutable_bio.get())); } @@ -61,7 +61,7 @@ TEST_F("Mutable BIO_write moves write cursor per invocation", Fixture) { ASSERT_EQUAL(4, ret); EXPECT_EQUAL(12, BIO_pending(f.mutable_bio.get())); - EXPECT_EQUAL(to_write, vespalib::stringref(f.tmp_buf.data(), to_write.size())); + EXPECT_EQUAL(to_write, std::string_view(f.tmp_buf.data(), to_write.size())); } TEST_F("Const BIO_read reads from associated buffer", Fixture) { @@ -72,7 +72,7 @@ TEST_F("Const BIO_read reads from associated buffer", Fixture) { EXPECT_EQUAL(static_cast<int>(to_read.size()), ret); EXPECT_EQUAL(ret, static_cast<int>(to_read.size())); - EXPECT_EQUAL(to_read, vespalib::stringref(f.tmp_buf.data(), to_read.size())); + EXPECT_EQUAL(to_read, std::string_view(f.tmp_buf.data(), to_read.size())); } TEST_F("Const BIO_read moves read cursor per invocation", Fixture) { @@ -90,7 +90,7 @@ TEST_F("Const BIO_read moves read cursor per invocation", Fixture) { ASSERT_EQUAL(6, ret); EXPECT_EQUAL(0, BIO_pending(f.const_bio.get())); - EXPECT_EQUAL(to_read, vespalib::stringref(f.tmp_buf.data(), to_read.size())); + EXPECT_EQUAL(to_read, std::string_view(f.tmp_buf.data(), to_read.size())); } TEST_F("Const BIO read EOF returns -1 by default and sets BIO retry flag", Fixture) { diff --git a/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp b/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp index 0912afde250..585339e7b57 100644 --- a/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp +++ b/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp @@ -59,9 +59,9 @@ void print_decode_result(const char* mode, const DecodeResult& res) { decode_state_to_str(res.state)); } -TransportSecurityOptions ts_from_pems(vespalib::stringref ca_certs_pem, - vespalib::stringref cert_chain_pem, - vespalib::stringref private_key_pem) +TransportSecurityOptions ts_from_pems(std::string_view ca_certs_pem, + std::string_view cert_chain_pem, + std::string_view private_key_pem) { auto ts_builder = TransportSecurityOptions::Params(). ca_certs_pem(ca_certs_pem). @@ -128,7 +128,7 @@ struct Fixture { return create_openssl_codec(ctx, mode, SocketSpec::invalid); } - static EncodeResult do_encode(CryptoCodec& codec, Output& buffer, vespalib::stringref plaintext) { + static EncodeResult do_encode(CryptoCodec& codec, Output& buffer, std::string_view plaintext) { auto out = buffer.reserve(codec.min_encode_buffer_size()); auto enc_res = codec.encode(plaintext.data(), plaintext.size(), out.data, out.size); buffer.commit(enc_res.bytes_produced); @@ -146,13 +146,13 @@ struct Fixture { return enc_res; } - EncodeResult client_encode(vespalib::stringref plaintext) { + EncodeResult client_encode(std::string_view plaintext) { auto res = do_encode(*client, client_to_server, plaintext); print_encode_result("client", res); return res; } - EncodeResult server_encode(vespalib::stringref plaintext) { + EncodeResult server_encode(std::string_view plaintext) { auto res = do_encode(*server, server_to_client, plaintext); print_encode_result("server", res); return res; diff --git a/vespalib/src/tests/net/tls/policy_checking_certificate_verifier/policy_checking_certificate_verifier_test.cpp b/vespalib/src/tests/net/tls/policy_checking_certificate_verifier/policy_checking_certificate_verifier_test.cpp index b80151e9ccf..7070e4136e5 100644 --- a/vespalib/src/tests/net/tls/policy_checking_certificate_verifier/policy_checking_certificate_verifier_test.cpp +++ b/vespalib/src/tests/net/tls/policy_checking_certificate_verifier/policy_checking_certificate_verifier_test.cpp @@ -8,22 +8,22 @@ using namespace vespalib; using namespace vespalib::net::tls; -bool dns_glob_matches(vespalib::stringref pattern, vespalib::stringref string_to_check) { +bool dns_glob_matches(std::string_view pattern, std::string_view string_to_check) { auto glob = CredentialMatchPattern::create_from_dns_glob(pattern); return glob->matches(string_to_check); } -bool uri_glob_matches(vespalib::stringref pattern, vespalib::stringref string_to_check) { +bool uri_glob_matches(std::string_view pattern, std::string_view string_to_check) { auto glob = CredentialMatchPattern::create_from_uri_glob(pattern); return glob->matches(string_to_check); } -void verify_all_glob_types_match(vespalib::stringref pattern, vespalib::stringref string_to_check) { +void verify_all_glob_types_match(std::string_view pattern, std::string_view string_to_check) { EXPECT_TRUE(dns_glob_matches(pattern, string_to_check)); EXPECT_TRUE(uri_glob_matches(pattern, string_to_check)); } -void verify_all_glob_types_mismatch(vespalib::stringref pattern, vespalib::stringref string_to_check) { +void verify_all_glob_types_mismatch(std::string_view pattern, std::string_view string_to_check) { EXPECT_FALSE(dns_glob_matches(pattern, string_to_check)); EXPECT_FALSE(uri_glob_matches(pattern, string_to_check)); } @@ -117,7 +117,7 @@ PeerCredentials creds_with_uri_sans(std::vector<vespalib::string> uri_sans) { return creds; } -PeerCredentials creds_with_cn(vespalib::stringref cn) { +PeerCredentials creds_with_cn(std::string_view cn) { PeerCredentials creds; creds.common_name = cn; return creds; diff --git a/vespalib/src/tests/nexus/CMakeLists.txt b/vespalib/src/tests/nexus/CMakeLists.txt deleted file mode 100644 index 1cc0e8d31fd..00000000000 --- a/vespalib/src/tests/nexus/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_nexus_test_app TEST - SOURCES - nexus_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_nexus_test_app COMMAND vespalib_nexus_test_app) diff --git a/vespalib/src/tests/objects/nbostream/nbostream_test.cpp b/vespalib/src/tests/objects/nbostream/nbostream_test.cpp index 91c83656353..b8b12d508a2 100644 --- a/vespalib/src/tests/objects/nbostream/nbostream_test.cpp +++ b/vespalib/src/tests/objects/nbostream/nbostream_test.cpp @@ -195,9 +195,9 @@ TEST_F("Test serializing c string", Fixture) EXPECT_EQUAL(exp, f._stream); } -TEST_F("Test serializing stringref", Fixture) +TEST_F("Test serializing std::string_view", Fixture) { - vespalib::stringref val("Hello"); + std::string_view val("Hello"); ExpBuffer exp({ 0x00, 0x00, 0x00, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f }); f._stream << val; EXPECT_EQUAL(exp, f._stream); diff --git a/vespalib/src/tests/objects/objectdump/objectdump.cpp b/vespalib/src/tests/objects/objectdump/objectdump.cpp index f2f4920c37b..e5497d73e69 100644 --- a/vespalib/src/tests/objects/objectdump/objectdump.cpp +++ b/vespalib/src/tests/objects/objectdump/objectdump.cpp @@ -41,7 +41,7 @@ struct Bar : public Base float _float; double _double; vespalib::string _string; - Bar() : _bool(true), _int8(-1), _uint8(1), _int16(-2), _uint16(2), + Bar() noexcept : _bool(true), _int8(-1), _uint8(1), _int16(-2), _uint16(2), _int32(-4), _uint32(4), _int64(-8), _uint64(8), _float(2.5), _double(2.75), _string("bla bla") {} @@ -76,20 +76,20 @@ struct Foo : public Base std::vector<IdentifiablePtr<Base> > _list2; Foo(); - ~Foo(); + ~Foo() override; Foo *clone() const override { return new Foo(*this); } void visitMembers(ObjectVisitor &v) const override; }; -Foo::~Foo() { } +Foo::~Foo() = default; Foo::Foo() : _objMember(), _objMember2(), _objPtr(0), _list(), _list2() { - _list.push_back(Bar()); - _list.push_back(Bar()); - _list.push_back(Bar()); - _list2.push_back(Bar()); - _list2.push_back(Baz()); + _list.emplace_back(); + _list.emplace_back(); + _list.emplace_back(); + _list2.emplace_back(Bar()); + _list2.emplace_back(Baz()); } void diff --git a/vespalib/src/tests/portal/portal_test.cpp b/vespalib/src/tests/portal/portal_test.cpp index e5a6cc1572b..7657f5a65d9 100644 --- a/vespalib/src/tests/portal/portal_test.cpp +++ b/vespalib/src/tests/portal/portal_test.cpp @@ -32,7 +32,7 @@ vespalib::string do_http(int port, CryptoEngine::SP crypto, const vespalib::stri vespalib::string result; ssize_t res = conn->read(buf, sizeof(buf)); while (res > 0) { - result.append(vespalib::stringref(buf, res)); + result.append(std::string_view(buf, res)); res = conn->read(buf, sizeof(buf)); } ASSERT_EQUAL(res, 0); diff --git a/vespalib/src/tests/printable/.gitignore b/vespalib/src/tests/printable/.gitignore deleted file mode 100644 index e001a281449..00000000000 --- a/vespalib/src/tests/printable/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -printabletest -vespalib_printabletest_app diff --git a/vespalib/src/tests/printable/CMakeLists.txt b/vespalib/src/tests/printable/CMakeLists.txt deleted file mode 100644 index 4781e9b8f54..00000000000 --- a/vespalib/src/tests/printable/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_printabletest_app TEST - SOURCES - printabletest.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_printabletest_app COMMAND vespalib_printabletest_app) diff --git a/vespalib/src/tests/random/CMakeLists.txt b/vespalib/src/tests/random/CMakeLists.txt index 75d9ce75f1a..e79944f69ef 100644 --- a/vespalib/src/tests/random/CMakeLists.txt +++ b/vespalib/src/tests/random/CMakeLists.txt @@ -1,12 +1,4 @@ # Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_random_test_app TEST - SOURCES - random_test.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_random_test_app COMMAND vespalib_random_test_app) vespa_add_executable(vespalib_friendfinder_test_app SOURCES friendfinder.cpp diff --git a/vespalib/src/tests/ref_counted/CMakeLists.txt b/vespalib/src/tests/ref_counted/CMakeLists.txt deleted file mode 100644 index bbbcd7db67b..00000000000 --- a/vespalib/src/tests/ref_counted/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_ref_counted_test_app TEST - SOURCES - ref_counted_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_ref_counted_test_app COMMAND vespalib_ref_counted_test_app) diff --git a/vespalib/src/tests/require/CMakeLists.txt b/vespalib/src/tests/require/CMakeLists.txt deleted file mode 100644 index d4f2b305006..00000000000 --- a/vespalib/src/tests/require/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_require_test_app TEST - SOURCES - require_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_require_test_app COMMAND vespalib_require_test_app) diff --git a/vespalib/src/tests/sequencedtaskexecutor/adaptive_sequenced_executor_test.cpp b/vespalib/src/tests/sequencedtaskexecutor/adaptive_sequenced_executor_test.cpp index ef13421a6ec..230bdbc87a6 100644 --- a/vespalib/src/tests/sequencedtaskexecutor/adaptive_sequenced_executor_test.cpp +++ b/vespalib/src/tests/sequencedtaskexecutor/adaptive_sequenced_executor_test.cpp @@ -64,7 +64,7 @@ public: } }; -vespalib::stringref ZERO("0"); +std::string_view ZERO("0"); TEST_F("testExecute", Fixture) { std::shared_ptr<TestObj> tv(std::make_shared<TestObj>()); @@ -133,7 +133,7 @@ TEST_F("require that task with same string component id are serialized", Fixture namespace { -int detectSerializeFailure(Fixture &f, vespalib::stringref altComponentId, int tryLimit) +int detectSerializeFailure(Fixture &f, std::string_view altComponentId, int tryLimit) { int tryCnt = 0; for (tryCnt = 0; tryCnt < tryLimit; ++tryCnt) { diff --git a/vespalib/src/tests/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp b/vespalib/src/tests/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp index beed490c214..7943371c6b0 100644 --- a/vespalib/src/tests/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp +++ b/vespalib/src/tests/sequencedtaskexecutor/sequencedtaskexecutor_test.cpp @@ -72,7 +72,7 @@ public: } }; -vespalib::stringref ZERO("0"); +std::string_view ZERO("0"); TEST_F("testExecute", Fixture) { std::shared_ptr<TestObj> tv(std::make_shared<TestObj>()); @@ -159,7 +159,7 @@ TEST_F("require that task with same string component id are serialized", Fixture namespace { int -detectSerializeFailure(Fixture &f, vespalib::stringref altComponentId, int tryLimit) +detectSerializeFailure(Fixture &f, std::string_view altComponentId, int tryLimit) { int tryCnt = 0; for (tryCnt = 0; tryCnt < tryLimit; ++tryCnt) { diff --git a/vespalib/src/tests/sharedptr/.gitignore b/vespalib/src/tests/sharedptr/.gitignore deleted file mode 100644 index d6ea42f40fb..00000000000 --- a/vespalib/src/tests/sharedptr/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.depend -Makefile -ptrholder_test -sharedptr_test -vespalib_ptrholder_test_app diff --git a/vespalib/src/tests/sharedptr/CMakeLists.txt b/vespalib/src/tests/sharedptr/CMakeLists.txt deleted file mode 100644 index 6e038ed31c5..00000000000 --- a/vespalib/src/tests/sharedptr/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_ptrholder_test_app TEST - SOURCES - ptrholder.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_ptrholder_test_app COMMAND vespalib_ptrholder_test_app) diff --git a/vespalib/src/tests/slime/are_equal/slime_are_equal_test.cpp b/vespalib/src/tests/slime/are_equal/slime_are_equal_test.cpp index 4751d51958a..07509524775 100644 --- a/vespalib/src/tests/slime/are_equal/slime_are_equal_test.cpp +++ b/vespalib/src/tests/slime/are_equal/slime_are_equal_test.cpp @@ -13,7 +13,7 @@ using namespace vespalib::slime::convenience; using vespalib::make_string_short::fmt; using vespalib::slime::NIX; -using Path = std::vector<std::variant<size_t,vespalib::stringref>>; +using Path = std::vector<std::variant<size_t,std::string_view>>; using Hook = std::function<bool(const Path &, const Inspector &, const Inspector &)>; using vespalib::slime::Inspector; @@ -92,7 +92,7 @@ vespalib::string path_to_str(const Path &path) { } std::visit(vespalib::overload{ [&str](size_t value)noexcept{ str.append(fmt("%zu", value)); }, - [&str](vespalib::stringref value)noexcept{ str.append(value); }}, item); + [&str](std::string_view value)noexcept{ str.append(value); }}, item); } str.append("]"); return str; diff --git a/vespalib/src/tests/small_vector/CMakeLists.txt b/vespalib/src/tests/small_vector/CMakeLists.txt deleted file mode 100644 index f40a708402d..00000000000 --- a/vespalib/src/tests/small_vector/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_small_vector_test_app TEST - SOURCES - small_vector_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_small_vector_test_app COMMAND vespalib_small_vector_test_app) diff --git a/vespalib/src/tests/state_server/state_server_test.cpp b/vespalib/src/tests/state_server/state_server_test.cpp index 18dc54188ef..5c27f585d8d 100644 --- a/vespalib/src/tests/state_server/state_server_test.cpp +++ b/vespalib/src/tests/state_server/state_server_test.cpp @@ -57,7 +57,7 @@ get_body_and_content_type(const JsonGetHandler &handler, net::ConnectionAuthContext dummy_ctx(net::tls::PeerCredentials(), net::tls::CapabilitySet::all()); auto res = handler.get(host, path, params, dummy_ctx); if (res.ok()) { - return {res.payload(), res.content_type()}; + return {vespalib::string(res.payload()), vespalib::string(res.content_type())}; } return {}; } diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp index cd710c0adb4..048e6ab3fee 100644 --- a/vespalib/src/tests/stllike/asciistream_test.cpp +++ b/vespalib/src/tests/stllike/asciistream_test.cpp @@ -20,7 +20,7 @@ verifyBothWays(T value, const char * expected, const vespalib::string& label) SCOPED_TRACE(label); asciistream os; os << value; - EXPECT_EQ(os.str(), string(expected)); + EXPECT_EQ(os.view(), string(expected)); EXPECT_EQ(os.size(), strlen(expected)); { T v; @@ -48,7 +48,7 @@ verify(T first, T second, const char * firstResult, const char * secondResult, c std::ostringstream ss; os << first; ss << first; - EXPECT_EQ(os.str(), string(firstResult)); + EXPECT_EQ(os.view(), string(firstResult)); EXPECT_EQ(os.size(), strlen(firstResult)); EXPECT_EQ(ss.str().size(), strlen(firstResult)); EXPECT_EQ(strcmp(ss.str().c_str(), firstResult), 0); @@ -102,7 +102,7 @@ TEST(AsciistreamTest, test_illegal_numbers) float f(0); EXPECT_THROW(is >> f, IllegalArgumentException); EXPECT_EQ(40u, is.size()); - vespalib::string tmp = is.str(); + std::string_view tmp = is.view(); is << "e" << tmp; EXPECT_EQ(81u, is.size()); double d(0); @@ -153,33 +153,33 @@ TEST(AsciistreamTest, test_copy_construct) asciistream os; os << "test1"; asciistream os2(os); - EXPECT_EQ(os.str(), os2.str()); + EXPECT_EQ(os.view(), os2.view()); os2 << " test2"; - EXPECT_FALSE(os.str() == os2.str()); + EXPECT_FALSE(os.view() == os2.view()); asciistream os3(os); os3 = os2; - EXPECT_EQ(os2.str(), os3.str()); + EXPECT_EQ(os2.view(), os3.view()); os.swap(os2); - EXPECT_EQ(os.str(), os3.str()); - EXPECT_FALSE(os3.str() == os2.str()); + EXPECT_EQ(os.view(), os3.view()); + EXPECT_FALSE(os3.view() == os2.view()); os.swap(os2); - EXPECT_TRUE(os3.str() == os2.str()); + EXPECT_TRUE(os3.view() == os2.view()); } TEST(AsciistreamTest, test_move_is_well_defined) { asciistream read_only("hello world"); asciistream dest(std::move(read_only)); - EXPECT_EQ("hello world", dest.str()); + EXPECT_EQ("hello world", dest.view()); read_only = asciistream("a string long enough to not be short string optimized"); dest = std::move(read_only); - EXPECT_EQ("a string long enough to not be short string optimized", dest.str()); + EXPECT_EQ("a string long enough to not be short string optimized", dest.view()); asciistream written_src; written_src << "a foo walks into a bar"; dest = std::move(written_src); - EXPECT_EQ("a foo walks into a bar", dest.str()); + EXPECT_EQ("a foo walks into a bar", dest.view()); } TEST(AsciistreamTest, test_integer_manip) @@ -220,7 +220,7 @@ TEST(AsciistreamTest, test_integer_manip) // Also test that number base is restored OK after ptr print os << dec << ' ' << fooptr << ' ' << 1234; ss << std::dec << ' ' << fooptr << ' ' << 1234; - EXPECT_EQ(std::string("10 10 a b 12 0b1010 0x1badbadc0ffee 1234"), os.str()); + EXPECT_EQ(std::string("10 10 a b 12 0b1010 0x1badbadc0ffee 1234"), os.view()); EXPECT_EQ(std::string("10 10 a b 12 0x1badbadc0ffee 1234"), ss.str()); int i = 0; @@ -230,7 +230,7 @@ TEST(AsciistreamTest, test_integer_manip) std_istr >> i; EXPECT_EQ(1234, i); - stringref firstfour(digits, 4); + std::string_view firstfour(digits, 4); asciistream istr(firstfour); istr >> i; EXPECT_EQ(1234, i); @@ -319,7 +319,7 @@ TEST(AsciistreamTest, test_string) { asciistream oss; oss << ss << vs; - EXPECT_EQ("aa", oss.str()); + EXPECT_EQ("aa", oss.view()); } { std::istringstream iss("b c"); @@ -400,7 +400,7 @@ TEST(AsciistreamTest, test_get_line) mystream << format; \ if (precision > 0) mystream << asciistream::Precision(precision); \ mystream << value; \ - EXPECT_EQ(expected, mystream.str()); \ + EXPECT_EQ(expected, mystream.view()); \ } TEST(AsciistreamTest, test_double) diff --git a/vespalib/src/tests/stllike/string_test.cpp b/vespalib/src/tests/stllike/string_test.cpp index 509c71b1641..41beee508d3 100644 --- a/vespalib/src/tests/stllike/string_test.cpp +++ b/vespalib/src/tests/stllike/string_test.cpp @@ -291,7 +291,7 @@ TEST("testString") { EXPECT_EQUAL(3u, s.rfind("ab")); } { - stringref s("abcabca"); + std::string_view s("abcabca"); EXPECT_EQUAL(string::npos, s.find('g')); EXPECT_EQUAL(string::npos, s.rfind('g')); EXPECT_EQUAL(0u, s.find('a')); @@ -302,26 +302,27 @@ TEST("testString") { EXPECT_EQUAL(5u, s.rfind("ca")); EXPECT_EQUAL(0u, s.find("ab")); EXPECT_EQUAL(3u, s.rfind("ab")); - stringref s2("abc"); + std::string_view s2("abc"); EXPECT_EQUAL(2u, s2.rfind('c')); EXPECT_EQUAL(1u, s2.rfind('b')); EXPECT_EQUAL(0u, s2.rfind('a')); EXPECT_EQUAL(string::npos, s2.rfind('d')); } - EXPECT_EQUAL("a" + stringref("b"), string("ab")); + EXPECT_EQUAL("a" + std::string_view("b"), string("ab")); EXPECT_EQUAL("a" + string("b"), string("ab")); EXPECT_EQUAL(string("a") + string("b"), string("ab")); - EXPECT_EQUAL(string("a") + stringref("b"), string("ab")); + EXPECT_EQUAL(string("a") + std::string_view("b"), string("ab")); EXPECT_EQUAL(string("a") + "b", string("ab")); - EXPECT_EQUAL(stringref("a") + stringref("b"), string("ab")); + EXPECT_EQUAL(std::string_view("a") + std::string_view("b"), string("ab")); // Test std::string conversion of empty string - stringref sref; + std::string_view sref; std::string stdString(sref); - EXPECT_TRUE(strcmp("", sref.data()) == 0); + EXPECT_EQUAL(nullptr, sref.data()); + EXPECT_TRUE(strcmp("", stdString.data()) == 0); stdString = "abc"; - stringref sref2(stdString); + std::string_view sref2(stdString); EXPECT_TRUE(stdString.c_str() == sref2.data()); EXPECT_TRUE(stdString == sref2); EXPECT_TRUE(sref2 == stdString); @@ -338,7 +339,7 @@ TEST("testString") { } { EXPECT_EQUAL(string("abc"), string("abcd", 3)); - EXPECT_EQUAL(string("abc"), string(stringref("abc"))); + EXPECT_EQUAL(string("abc"), string(std::string_view("abc"))); } { string s("abc"); @@ -350,7 +351,7 @@ TEST("testString") { EXPECT_EQUAL(string("c"), s.substr(2)); } { - stringref s("abc"); + std::string_view s("abc"); EXPECT_EQUAL(string("a"), s.substr(0,1)); EXPECT_EQUAL(string("b"), s.substr(1,1)); EXPECT_EQUAL(string("c"), s.substr(2,1)); @@ -461,10 +462,10 @@ TEST("test that small_string::pop_back works") { } -TEST("test that operator<() works with stringref versus string") { - vespalib::stringref sra("a"); +TEST("test that operator<() works with std::string_view versus string") { + std::string_view sra("a"); vespalib::string sa("a"); - vespalib::stringref srb("b"); + std::string_view srb("b"); vespalib::string sb("b"); EXPECT_FALSE(sra < sra); EXPECT_FALSE(sra < sa); @@ -498,9 +499,9 @@ TEST("starts_with has expected semantics for small_string") { EXPECT_FALSE(a.starts_with("oobar")); } -TEST("starts_with has expected semantics for stringref") { +TEST("starts_with has expected semantics for std::string_view") { vespalib::string a("foobar"); - vespalib::stringref ar(a); + std::string_view ar(a); EXPECT_TRUE(ar.starts_with("")); EXPECT_TRUE(ar.starts_with("foo")); EXPECT_TRUE(ar.starts_with("foobar")); diff --git a/vespalib/src/tests/time/CMakeLists.txt b/vespalib/src/tests/time/CMakeLists.txt index c4d22cc5b45..bcc0d8fc772 100644 --- a/vespalib/src/tests/time/CMakeLists.txt +++ b/vespalib/src/tests/time/CMakeLists.txt @@ -6,11 +6,3 @@ vespa_add_executable(vespalib_time_box_test_app TEST vespalib ) vespa_add_test(NAME vespalib_time_box_test_app COMMAND vespalib_time_box_test_app) -vespa_add_executable(vespalib_time_test_app TEST - SOURCES - time_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_time_test_app COMMAND vespalib_time_test_app) diff --git a/vespalib/src/tests/typify/CMakeLists.txt b/vespalib/src/tests/typify/CMakeLists.txt deleted file mode 100644 index d95c9fecd78..00000000000 --- a/vespalib/src/tests/typify/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_typify_test_app TEST - SOURCES - typify_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_typify_test_app COMMAND vespalib_typify_test_app) diff --git a/vespalib/src/tests/util/CMakeLists.txt b/vespalib/src/tests/util/CMakeLists.txt new file mode 100644 index 00000000000..fef048cc99c --- /dev/null +++ b/vespalib/src/tests/util/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +# Runner for unit tests written in gtest. +# NOTE: All new test classes should be added here. +vespa_add_executable(vespalib_util_gtest_runner_test_app TEST + SOURCES + gtest_runner.cpp + bfloat16_test.cpp + bits_test.cpp + cgroup_resource_limits_test.cpp + crc_test.cpp + crypto_test.cpp + eventbarrier.cpp + file_area_freelist_test.cpp + generation_hold_list_test.cpp + generationhandler_test.cpp + json.cpp + issue_test.cpp + memory_trap_test.cpp + mmap_file_allocator_factory_test.cpp + mmap_file_allocator_test.cpp + nexus_test.cpp + printabletest.cpp + ptrholder.cpp + random_test.cpp + rcuvector_test.cpp + ref_counted_test.cpp + require_test.cpp + size_literals_test.cpp + small_vector_test.cpp + static_string_test.cpp + string_escape_test.cpp + time_test.cpp + typify_test.cpp + xmlserializabletest.cpp + DEPENDS + vespalib + onnxruntime + GTest::GTest +) + +vespa_add_test( NAME vespalib_util_gtest_runner_test_app COMMAND vespalib_util_gtest_runner_test_app) diff --git a/vespalib/src/tests/util/bfloat16/CMakeLists.txt b/vespalib/src/tests/util/bfloat16/CMakeLists.txt deleted file mode 100644 index 72d6c8720d6..00000000000 --- a/vespalib/src/tests/util/bfloat16/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -if(EXISTS /opt/vespa-deps/include/onnxruntime/onnxruntime_cxx_api.h) -vespa_add_executable(vespalib_bfloat16_test_app TEST - SOURCES - bfloat16_test.cpp - DEPENDS - vespalib - onnxruntime - GTest::GTest -) -vespa_add_test(NAME vespalib_bfloat16_test_app COMMAND vespalib_bfloat16_test_app) -endif() diff --git a/vespalib/src/tests/util/bfloat16/bfloat16_test.cpp b/vespalib/src/tests/util/bfloat16_test.cpp index 196c5f98c9e..8b21cbad309 100644 --- a/vespalib/src/tests/util/bfloat16/bfloat16_test.cpp +++ b/vespalib/src/tests/util/bfloat16_test.cpp @@ -219,5 +219,3 @@ TEST(OnnxBFloat16Test, has_same_encoding) { printf("floats that are NaN in both vespalib and onnx: %d (0x%04x)\n", nan_count, nan_count); printf("total count (OK + NaN): %d (0x%04x)\n", ok_count + nan_count, ok_count + nan_count); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/bits/bits_test.cpp b/vespalib/src/tests/util/bits_test.cpp index 6b01b2cd63a..4132627a412 100644 --- a/vespalib/src/tests/bits/bits_test.cpp +++ b/vespalib/src/tests/util/bits_test.cpp @@ -56,5 +56,3 @@ void BitsTest::testBuffer() Bits::reverse(&a, sizeof(a)); EXPECT_EQ(a, b); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/cgroup_resource_limits/CMakeLists.txt b/vespalib/src/tests/util/cgroup_resource_limits/CMakeLists.txt deleted file mode 100644 index d7e99fcde29..00000000000 --- a/vespalib/src/tests/util/cgroup_resource_limits/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_cgroup_resource_limits_test_app TEST - SOURCES - cgroup_resource_limits_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_cgroup_resource_limits_test_app COMMAND vespalib_cgroup_resource_limits_test_app) diff --git a/vespalib/src/tests/util/cgroup_resource_limits/cgroup_resource_limits_test.cpp b/vespalib/src/tests/util/cgroup_resource_limits_test.cpp index 38e8467ff35..2528c56d211 100644 --- a/vespalib/src/tests/util/cgroup_resource_limits/cgroup_resource_limits_test.cpp +++ b/vespalib/src/tests/util/cgroup_resource_limits_test.cpp @@ -12,15 +12,16 @@ class CGroupResourceLimitsTest : public ::testing::Test protected: CGroupResourceLimitsTest(); ~CGroupResourceLimitsTest(); - void check_limits(const std::string &name, const std::optional<uint64_t>& memory_limit, const std::optional<uint32_t>& cpu_limit); + void check_limits(std::string_view name, const std::optional<uint64_t>& memory_limit, const std::optional<uint32_t>& cpu_limit); }; CGroupResourceLimitsTest::CGroupResourceLimitsTest() = default; CGroupResourceLimitsTest::~CGroupResourceLimitsTest() = default; void -CGroupResourceLimitsTest::check_limits(const std::string &base, const std::optional<uint64_t>& memory_limit, const std::optional<uint32_t>& cpu_limit) +CGroupResourceLimitsTest::check_limits(std::string_view subdir, const std::optional<uint64_t>& memory_limit, const std::optional<uint32_t>& cpu_limit) { + std::string base = "cgroup_resource_limits/" + subdir; auto src_base = TEST_PATH(base); CGroupResourceLimits cg_limits(src_base + "/cgroup", src_base + "/self"); EXPECT_EQ(memory_limit, cg_limits.get_memory_limit()); @@ -73,5 +74,3 @@ TEST_F(CGroupResourceLimitsTest, cgroup_v2_container) } } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/crc/crc_test.cpp b/vespalib/src/tests/util/crc_test.cpp index 82ad8b4c013..c9cec0a4ad5 100644 --- a/vespalib/src/tests/crc/crc_test.cpp +++ b/vespalib/src/tests/util/crc_test.cpp @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/util/crc.h> -#include <vespa/vespalib/gtest/gtest.h> #include <vector> +#include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; @@ -28,7 +28,7 @@ TEST(FCrcTest, test_correctness) TEST(CrcTest, benchmark) { constexpr size_t bufSz = 1024; - constexpr size_t numRep = 1000 * 1000; + constexpr size_t numRep = 100 * 1000; std::vector<char> a(numRep+bufSz); for(size_t i(0), m(a.size()); i < m; i++) { a[i] = i&0xff; @@ -42,5 +42,3 @@ TEST(CrcTest, benchmark) } printf("sum = %x\n", sum); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/crypto/crypto_test.cpp b/vespalib/src/tests/util/crypto_test.cpp index ed70414fbde..4cad16a7d63 100644 --- a/vespalib/src/tests/crypto/crypto_test.cpp +++ b/vespalib/src/tests/util/crypto_test.cpp @@ -33,5 +33,3 @@ TEST(CryptoTest, generated_x509_certificate_can_be_exported_to_pem_format) { } } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/eventbarrier/eventbarrier.cpp b/vespalib/src/tests/util/eventbarrier.cpp index 31db0e61fe7..a54f039fb00 100644 --- a/vespalib/src/tests/eventbarrier/eventbarrier.cpp +++ b/vespalib/src/tests/util/eventbarrier.cpp @@ -171,5 +171,3 @@ TEST(EventBarriarTest, test_reorder) EXPECT_EQ(eb.countEvents(), 0u); EXPECT_EQ(eb.countBarriers(), 0u); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/file_area_freelist/CMakeLists.txt b/vespalib/src/tests/util/file_area_freelist/CMakeLists.txt deleted file mode 100644 index 30303eaed21..00000000000 --- a/vespalib/src/tests/util/file_area_freelist/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_file_area_freelist_test_app TEST - SOURCES - file_area_freelist_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_file_area_freelist_test_app COMMAND vespalib_file_area_freelist_test_app) diff --git a/vespalib/src/tests/util/file_area_freelist/file_area_freelist_test.cpp b/vespalib/src/tests/util/file_area_freelist_test.cpp index 470680e0f8f..90161b76d49 100644 --- a/vespalib/src/tests/util/file_area_freelist/file_area_freelist_test.cpp +++ b/vespalib/src/tests/util/file_area_freelist_test.cpp @@ -97,6 +97,3 @@ TEST_F(FileAreaFreeListTest, can_use_part_of_free_area) EXPECT_EQ(5, _freelist.alloc(1)); EXPECT_EQ(bad_offset, _freelist.alloc(1)); } - - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/generation_hold_list/CMakeLists.txt b/vespalib/src/tests/util/generation_hold_list/CMakeLists.txt deleted file mode 100644 index bf607a6fec6..00000000000 --- a/vespalib/src/tests/util/generation_hold_list/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_generation_hold_list_test_app TEST - SOURCES - generation_hold_list_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_generation_hold_list_test_app COMMAND vespalib_generation_hold_list_test_app) diff --git a/vespalib/src/tests/util/generation_hold_list/generation_hold_list_test.cpp b/vespalib/src/tests/util/generation_hold_list_test.cpp index 2d8da961433..e7bbe40856d 100644 --- a/vespalib/src/tests/util/generation_hold_list/generation_hold_list_test.cpp +++ b/vespalib/src/tests/util/generation_hold_list_test.cpp @@ -91,5 +91,3 @@ TEST_F(IntHoldListTest, reclaim_all_calls_callback_for_all_elements) assert_reclaim_all({3, 5}); assert_reclaim_all({}); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/generationhandler/.gitignore b/vespalib/src/tests/util/generationhandler/.gitignore deleted file mode 100644 index c98a32727d9..00000000000 --- a/vespalib/src/tests/util/generationhandler/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -generationhandler_test -vespalib_generationhandler_test_app diff --git a/vespalib/src/tests/util/generationhandler/CMakeLists.txt b/vespalib/src/tests/util/generationhandler/CMakeLists.txt deleted file mode 100644 index 10cb0b00060..00000000000 --- a/vespalib/src/tests/util/generationhandler/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_generationhandler_test_app TEST - SOURCES - generationhandler_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_generationhandler_test_app COMMAND vespalib_generationhandler_test_app) diff --git a/vespalib/src/tests/util/generationhandler/generationhandler_test.cpp b/vespalib/src/tests/util/generationhandler_test.cpp index 383a46fbef9..5b2a69f95ea 100644 --- a/vespalib/src/tests/util/generationhandler/generationhandler_test.cpp +++ b/vespalib/src/tests/util/generationhandler_test.cpp @@ -133,5 +133,3 @@ TEST_F(GenerationHandlerTest, require_that_generation_can_grow_large) } } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/gtest_runner.cpp b/vespalib/src/tests/util/gtest_runner.cpp new file mode 100644 index 00000000000..c2e1d07b60c --- /dev/null +++ b/vespalib/src/tests/util/gtest_runner.cpp @@ -0,0 +1,8 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/vespalib/gtest/gtest.h> + +#include <vespa/log/log.h> +LOG_SETUP("vespalib_util_gtest_runner"); + +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/issue/issue_test.cpp b/vespalib/src/tests/util/issue_test.cpp index 366c7a64df9..f2a3622156c 100644 --- a/vespalib/src/tests/issue/issue_test.cpp +++ b/vespalib/src/tests/util/issue_test.cpp @@ -83,5 +83,3 @@ TEST(IssueTest, alternative_report_functions) { } EXPECT_EQ(my_handler.list, make_list({"str", "fmt_msg_7", "exception"})); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/json/json.cpp b/vespalib/src/tests/util/json.cpp index 024d9045cc1..f661ba7c7ef 100644 --- a/vespalib/src/tests/json/json.cpp +++ b/vespalib/src/tests/util/json.cpp @@ -1,9 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/jsonstream.h> #include <vespa/vespalib/util/jsonexception.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; @@ -14,77 +14,77 @@ TEST(JSONTest, test_json_writer_values) { // bool js.appendBool(true); - EXPECT_EQ(js.toString(), "true"); + EXPECT_EQ(js.view(), "true"); js.clear().appendBool(false); - EXPECT_EQ(js.toString(), "false"); + EXPECT_EQ(js.view(), "false"); } { // double js.clear().appendDouble(1234.5678); - EXPECT_EQ(js.toString(), "1234.5678"); + EXPECT_EQ(js.view(), "1234.5678"); js.clear().appendDouble(-1234.5678); - EXPECT_EQ(js.toString(), "-1234.5678"); + EXPECT_EQ(js.view(), "-1234.5678"); js.clear().appendDouble(0.0); - EXPECT_EQ(js.toString(), "0.0"); + EXPECT_EQ(js.view(), "0.0"); js.clear().appendDouble(0.00000000012345678912356789123456789); - EXPECT_EQ(js.toString(), "1.234567891235679e-10"); + EXPECT_EQ(js.view(), "1.234567891235679e-10"); js.clear().appendDouble(std::numeric_limits<double>::max()); - EXPECT_EQ(js.toString(), "1.797693134862316e+308"); + EXPECT_EQ(js.view(), "1.797693134862316e+308"); js.clear().appendDouble(std::numeric_limits<double>::min()); - EXPECT_EQ(js.toString(), "2.225073858507201e-308"); + EXPECT_EQ(js.view(), "2.225073858507201e-308"); js.clear().appendDouble(1.0 * (uint64_t(1) << 53)); - EXPECT_EQ(js.toString(), "9007199254740992.0"); + EXPECT_EQ(js.view(), "9007199254740992.0"); js.clear().appendDouble(1000); - EXPECT_EQ(js.toString(), "1000.0"); + EXPECT_EQ(js.view(), "1000.0"); } { // float js.clear().appendFloat(1234.5678f); - EXPECT_EQ(js.toString(), "1234.5677"); + EXPECT_EQ(js.view(), "1234.5677"); js.clear().appendFloat(-1234.5678f); - EXPECT_EQ(js.toString(), "-1234.5677"); + EXPECT_EQ(js.view(), "-1234.5677"); js.clear().appendFloat(0.0f); - EXPECT_EQ(js.toString(), "0.0"); + EXPECT_EQ(js.view(), "0.0"); js.clear().appendFloat(0.00000000012345678912356789123456789f); - EXPECT_EQ(js.toString(), "1.2345679e-10"); + EXPECT_EQ(js.view(), "1.2345679e-10"); js.clear().appendFloat(std::numeric_limits<float>::max()); - EXPECT_EQ(js.toString(), "3.4028235e+38"); + EXPECT_EQ(js.view(), "3.4028235e+38"); js.clear().appendFloat(std::numeric_limits<float>::min()); - EXPECT_EQ(js.toString(), "1.1754944e-38"); + EXPECT_EQ(js.view(), "1.1754944e-38"); js.clear().appendFloat(1.0 * (uint64_t(1) << 24)); - EXPECT_EQ(js.toString(), "16777216.0"); + EXPECT_EQ(js.view(), "16777216.0"); js.clear().appendFloat(1000); - EXPECT_EQ(js.toString(), "1000.0"); + EXPECT_EQ(js.view(), "1000.0"); } { // long js.clear().appendInt64(4294967296ll); - EXPECT_EQ(js.toString(), "4294967296"); + EXPECT_EQ(js.view(), "4294967296"); js.clear().appendInt64(-4294967296ll); - EXPECT_EQ(js.toString(), "-4294967296"); + EXPECT_EQ(js.view(), "-4294967296"); } { // string js.clear().appendString("string"); - EXPECT_EQ(js.toString(), "\"string\""); + EXPECT_EQ(js.view(), "\"string\""); } { // NULL js.clear().appendNull(); - EXPECT_EQ(js.toString(), "null"); + EXPECT_EQ(js.view(), "null"); } { // quote js.clear().appendString("x\"y"); - EXPECT_EQ(js.toString(), "\"x\\\"y\""); + EXPECT_EQ(js.view(), "\"x\\\"y\""); js.clear().appendString("x\\y"); - EXPECT_EQ(js.toString(), "\"x\\\\y\""); + EXPECT_EQ(js.view(), "\"x\\\\y\""); js.clear().appendString("x/y"); - EXPECT_EQ(js.toString(), "\"x/y\""); + EXPECT_EQ(js.view(), "\"x/y\""); js.clear().appendString("x\by"); - EXPECT_EQ(js.toString(), "\"x\\by\""); + EXPECT_EQ(js.view(), "\"x\\by\""); js.clear().appendString("x\fy"); - EXPECT_EQ(js.toString(), "\"x\\fy\""); + EXPECT_EQ(js.view(), "\"x\\fy\""); js.clear().appendString("x\ny"); - EXPECT_EQ(js.toString(), "\"x\\ny\""); + EXPECT_EQ(js.view(), "\"x\\ny\""); js.clear().appendString("x\ry"); - EXPECT_EQ(js.toString(), "\"x\\ry\""); + EXPECT_EQ(js.view(), "\"x\\ry\""); js.clear().appendString("x\ty"); - EXPECT_EQ(js.toString(), "\"x\\ty\""); + EXPECT_EQ(js.view(), "\"x\\ty\""); } } @@ -94,15 +94,15 @@ TEST(JSONTest, test_json_writer_object) { // single pair js.beginObject().appendKey("k1").appendInt64(1l).endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":1}"); + EXPECT_EQ(js.view(), "{\"k1\":1}"); } { // multiple pairs js.clear().beginObject().appendKey("k1").appendInt64(1l).appendKey("k2").appendInt64(2l).endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":1,\"k2\":2}"); + EXPECT_EQ(js.view(), "{\"k1\":1,\"k2\":2}"); } { // object in object js.clear().beginObject().appendKey("k1").beginObject().appendKey("k1.1").appendInt64(11l).endObject().endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":{\"k1.1\":11}}"); + EXPECT_EQ(js.view(), "{\"k1\":{\"k1.1\":11}}"); } { // object in object (multiple pairs) js.clear().beginObject(). @@ -117,19 +117,19 @@ TEST(JSONTest, test_json_writer_object) appendKey("k2.2").appendInt64(22l). endObject(). endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":{\"k1.1\":11,\"k1.2\":12},\"k2\":{\"k2.1\":21,\"k2.2\":22}}"); + EXPECT_EQ(js.view(), "{\"k1\":{\"k1.1\":11,\"k1.2\":12},\"k2\":{\"k2.1\":21,\"k2.2\":22}}"); } { // array in object js.clear().beginObject().appendKey("k1"). beginArray().appendInt64(1l).appendInt64(2l).endArray().endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":[1,2]}"); + EXPECT_EQ(js.view(), "{\"k1\":[1,2]}"); } { // array in object (multiple pairs) js.clear().beginObject(). appendKey("k1").beginArray().appendInt64(1l).appendInt64(2l).endArray(). appendKey("k2").beginArray().appendInt64(3l).appendInt64(4l).endArray(). endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":[1,2],\"k2\":[3,4]}"); + EXPECT_EQ(js.view(), "{\"k1\":[1,2],\"k2\":[3,4]}"); } } @@ -139,35 +139,35 @@ TEST(JSONTest, test_json_writer_array) { // single element js.beginArray().appendInt64(1l).endArray(); - EXPECT_EQ(js.toString(), "[1]"); + EXPECT_EQ(js.view(), "[1]"); } { // multiple elements js.clear().beginArray().appendInt64(1l).appendInt64(2l).endArray(); - EXPECT_EQ(js.toString(), "[1,2]"); + EXPECT_EQ(js.view(), "[1,2]"); } { // array in array js.clear().beginArray().beginArray().appendInt64(1l).endArray().endArray(); - EXPECT_EQ(js.toString(), "[[1]]"); + EXPECT_EQ(js.view(), "[[1]]"); } { // array in array (multiple elements) js.clear().beginArray(). beginArray().appendInt64(1l).appendInt64(2l).endArray(). beginArray().appendInt64(3l).appendInt64(4l).endArray(). endArray(); - EXPECT_EQ(js.toString(), "[[1,2],[3,4]]"); + EXPECT_EQ(js.view(), "[[1,2],[3,4]]"); } { // object in array js.clear().beginArray(). beginObject().appendKey("k1").appendInt64(1l).endObject(). endArray(); - EXPECT_EQ(js.toString(), "[{\"k1\":1}]"); + EXPECT_EQ(js.view(), "[{\"k1\":1}]"); } { // object in array (multiple elements) js.clear().beginArray(). beginObject().appendKey("k1").appendInt64(1l).appendKey("k2").appendInt64(2l).endObject(). beginObject().appendKey("k3").appendInt64(3l).appendKey("k4").appendInt64(4l).endObject(). endArray(); - EXPECT_EQ(js.toString(), "[{\"k1\":1,\"k2\":2},{\"k3\":3,\"k4\":4}]"); + EXPECT_EQ(js.view(), "[{\"k1\":1,\"k2\":2},{\"k3\":3,\"k4\":4}]"); } } @@ -249,7 +249,7 @@ TEST(JSONTest, test_json_writer_complex) js.endArray(); } js.endObject(); - EXPECT_EQ(js.toString(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":7,\"k3.2\":[8,9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); + EXPECT_EQ(js.view(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":7,\"k3.2\":[8,9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); } namespace { @@ -291,7 +291,7 @@ TEST(JSONTest, test_json_stream) Builder b; b.build(stream); stream.finalize(); - EXPECT_EQ(as.str(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":-7,\"k3.2\":[-8,-9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); + EXPECT_EQ(as.view(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":-7,\"k3.2\":[-8,-9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); } TEST(JSONTest, test_json_stream_errors) @@ -426,6 +426,3 @@ TEST(JSONTest, test_json_stream_state_reporting) << End(); EXPECT_EQ("Current: Finalized", stream.getJsonStreamState()); } - -GTEST_MAIN_RUN_ALL_TESTS() - diff --git a/vespalib/src/tests/util/md5/md5_test.cpp b/vespalib/src/tests/util/md5/md5_test.cpp index ce48aeb5c7c..a1b0c1ce311 100644 --- a/vespalib/src/tests/util/md5/md5_test.cpp +++ b/vespalib/src/tests/util/md5/md5_test.cpp @@ -6,7 +6,7 @@ namespace vespalib { -string md5_hash_of(stringref buffer) { +string md5_hash_of(std::string_view buffer) { unsigned char hash_out[16]; // Always 128 bits. fastc_md5sum(buffer.data(), buffer.size(), hash_out); asciistream os; diff --git a/vespalib/src/tests/util/memory_trap/CMakeLists.txt b/vespalib/src/tests/util/memory_trap/CMakeLists.txt deleted file mode 100644 index cc38296a928..00000000000 --- a/vespalib/src/tests/util/memory_trap/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_util_memory_trap_test_app TEST - SOURCES - memory_trap_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_util_memory_trap_test_app COMMAND vespalib_util_memory_trap_test_app) diff --git a/vespalib/src/tests/util/memory_trap/memory_trap_test.cpp b/vespalib/src/tests/util/memory_trap_test.cpp index a220e81f3a3..d963792e857 100644 --- a/vespalib/src/tests/util/memory_trap/memory_trap_test.cpp +++ b/vespalib/src/tests/util/memory_trap_test.cpp @@ -57,5 +57,3 @@ TEST_F(MemoryTrapTest, read_from_hw_backed_trap_crashes_process) { do_not_optimize_away(dummy); // never reached },""); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/mmap_file_allocator/.gitignore b/vespalib/src/tests/util/mmap_file_allocator/.gitignore deleted file mode 100644 index a18e9aac589..00000000000 --- a/vespalib/src/tests/util/mmap_file_allocator/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/mmap-file-allocator-factory-dir diff --git a/vespalib/src/tests/util/mmap_file_allocator/CMakeLists.txt b/vespalib/src/tests/util/mmap_file_allocator/CMakeLists.txt deleted file mode 100644 index c671b4df572..00000000000 --- a/vespalib/src/tests/util/mmap_file_allocator/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_mmap_file_allocator_test_app TEST - SOURCES - mmap_file_allocator_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_mmap_file_allocator_test_app COMMAND vespalib_mmap_file_allocator_test_app) diff --git a/vespalib/src/tests/util/mmap_file_allocator_factory/.gitignore b/vespalib/src/tests/util/mmap_file_allocator_factory/.gitignore deleted file mode 100644 index a18e9aac589..00000000000 --- a/vespalib/src/tests/util/mmap_file_allocator_factory/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/mmap-file-allocator-factory-dir diff --git a/vespalib/src/tests/util/mmap_file_allocator_factory/CMakeLists.txt b/vespalib/src/tests/util/mmap_file_allocator_factory/CMakeLists.txt deleted file mode 100644 index 03fbd04821b..00000000000 --- a/vespalib/src/tests/util/mmap_file_allocator_factory/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_mmap_file_allocator_factory_test_app TEST - SOURCES - mmap_file_allocator_factory_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_mmap_file_allocator_factory_test_app COMMAND vespalib_mmap_file_allocator_factory_test_app) diff --git a/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp b/vespalib/src/tests/util/mmap_file_allocator_factory_test.cpp index bda19a143d3..394ecd2df27 100644 --- a/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp +++ b/vespalib/src/tests/util/mmap_file_allocator_factory_test.cpp @@ -46,5 +46,3 @@ TEST(MmapFileAllocatorFactoryTest, nonempty_dir_gives_allocator) MmapFileAllocatorFactory::instance().setup(""); std::filesystem::remove_all(std::filesystem::path(basedir)); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp b/vespalib/src/tests/util/mmap_file_allocator_test.cpp index cf6227de4db..e986c976643 100644 --- a/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp +++ b/vespalib/src/tests/util/mmap_file_allocator_test.cpp @@ -129,5 +129,3 @@ TEST_P(MmapFileAllocatorTest, reuse_file_offset_works) EXPECT_EQ(0, memcmp(buf.data, world.c_str(), world.size() + 1)); } } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/nexus/nexus_test.cpp b/vespalib/src/tests/util/nexus_test.cpp index 2bf52cf448e..27559216a1a 100644 --- a/vespalib/src/tests/nexus/nexus_test.cpp +++ b/vespalib/src/tests/util/nexus_test.cpp @@ -83,5 +83,3 @@ TEST(NexusTest, example_multi_threaded_unit_test) { EXPECT_EQ(a, 5); EXPECT_EQ(b, 7); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/printable/printabletest.cpp b/vespalib/src/tests/util/printabletest.cpp index 5b6c0058bf0..b3f35ee1d5e 100644 --- a/vespalib/src/tests/printable/printabletest.cpp +++ b/vespalib/src/tests/util/printabletest.cpp @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/printable.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/gtest/gtest.h> struct Foo : public vespalib::Printable { int val; @@ -108,7 +108,7 @@ TEST(PrintableTest, test_ascii_variant) { vespalib::asciistream as; as << foo; - EXPECT_EQ("19", as.str()); + EXPECT_EQ("19", as.view()); std::ostringstream ost; ost << foo; @@ -123,12 +123,10 @@ TEST(PrintableTest, test_ascii_variant) { vespalib::asciistream as; as << bar; - EXPECT_EQ("3", as.str()); + EXPECT_EQ("3", as.view()); std::ostringstream ost; ost << bar; EXPECT_EQ("3", ost.str()); } } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/sharedptr/ptrholder.cpp b/vespalib/src/tests/util/ptrholder.cpp index e6d1710247b..cd8cd50509a 100644 --- a/vespalib/src/tests/sharedptr/ptrholder.cpp +++ b/vespalib/src/tests/util/ptrholder.cpp @@ -74,5 +74,3 @@ TEST(PtrHolderTest, test_simple) EXPECT_TRUE(data.ctorCnt == 2); EXPECT_TRUE(data.dtorCnt == 2); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/random/random_test.cpp b/vespalib/src/tests/util/random_test.cpp index 34b4e3d0389..49ce3931b53 100644 --- a/vespalib/src/tests/random/random_test.cpp +++ b/vespalib/src/tests/util/random_test.cpp @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/random.h> +#include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; @@ -133,5 +133,3 @@ TEST(RandoMTest, test_normal_distribution) EXPECT_TRUE(buckets[10] > buckets[0]); EXPECT_TRUE(buckets[90] > buckets[100]); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/rcuvector/.gitignore b/vespalib/src/tests/util/rcuvector/.gitignore deleted file mode 100644 index 2c1661a8461..00000000000 --- a/vespalib/src/tests/util/rcuvector/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.depend -Makefile -rcuvector_test -vespalib_rcuvector_test_app - diff --git a/vespalib/src/tests/util/rcuvector/CMakeLists.txt b/vespalib/src/tests/util/rcuvector/CMakeLists.txt deleted file mode 100644 index ddc572ca825..00000000000 --- a/vespalib/src/tests/util/rcuvector/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_rcuvector_test_app TEST - SOURCES - rcuvector_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_rcuvector_test_app COMMAND vespalib_rcuvector_test_app) diff --git a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp b/vespalib/src/tests/util/rcuvector_test.cpp index 134c697bd3f..28b8bcdad06 100644 --- a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp +++ b/vespalib/src/tests/util/rcuvector_test.cpp @@ -516,5 +516,3 @@ TEST(RcuVectorTest, single_writer_four_readers) StressFixture f; f.run_test(20000, 4); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/ref_counted/ref_counted_test.cpp b/vespalib/src/tests/util/ref_counted_test.cpp index eb85f7b55f9..d3469dad3c9 100644 --- a/vespalib/src/tests/ref_counted/ref_counted_test.cpp +++ b/vespalib/src/tests/util/ref_counted_test.cpp @@ -264,5 +264,3 @@ TEST(RefCountedTest, with_threads) { gate.countDown(); pool.join(); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/require/require_test.cpp b/vespalib/src/tests/util/require_test.cpp index 3acfa940a12..8ad8c225f08 100644 --- a/vespalib/src/tests/require/require_test.cpp +++ b/vespalib/src/tests/util/require_test.cpp @@ -168,7 +168,3 @@ TEST(RequireTest, explicit_require_failure) { } }, E); } - -//----------------------------------------------------------------------------- - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/size_literals/CMakeLists.txt b/vespalib/src/tests/util/size_literals/CMakeLists.txt deleted file mode 100644 index 0c32d81482c..00000000000 --- a/vespalib/src/tests/util/size_literals/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_size_literals_test_app TEST - SOURCES - size_literals_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_size_literals_test_app COMMAND vespalib_size_literals_test_app) diff --git a/vespalib/src/tests/util/size_literals/size_literals_test.cpp b/vespalib/src/tests/util/size_literals_test.cpp index 93a0ee5cdb7..8356ebc0351 100644 --- a/vespalib/src/tests/util/size_literals/size_literals_test.cpp +++ b/vespalib/src/tests/util/size_literals_test.cpp @@ -37,5 +37,3 @@ TEST(SizeLiteralsTest, simple_usage) EXPECT_TRUE(is_size_t(v42g)); EXPECT_TRUE(is_size_t(v42t)); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/small_vector/small_vector_test.cpp b/vespalib/src/tests/util/small_vector_test.cpp index 8924fe64eb9..0ef4091bd0c 100644 --- a/vespalib/src/tests/small_vector/small_vector_test.cpp +++ b/vespalib/src/tests/util/small_vector_test.cpp @@ -1,9 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/util/small_vector.h> -#include <vespa/vespalib/gtest/gtest.h> #include <vector> #include <map> +#include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; @@ -288,5 +288,3 @@ TEST(SmallVectorTest, pop_back) { } EXPECT_EQ(my_cnt, 0); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/static_string/CMakeLists.txt b/vespalib/src/tests/util/static_string/CMakeLists.txt deleted file mode 100644 index 508466d4c73..00000000000 --- a/vespalib/src/tests/util/static_string/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_static_string_test_app TEST - SOURCES - static_string_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_static_string_test_app COMMAND vespalib_static_string_test_app) diff --git a/vespalib/src/tests/util/static_string/static_string_test.cpp b/vespalib/src/tests/util/static_string_test.cpp index daaf7c0dae8..e5d9356e4dc 100644 --- a/vespalib/src/tests/util/static_string/static_string_test.cpp +++ b/vespalib/src/tests/util/static_string_test.cpp @@ -13,9 +13,9 @@ TEST(StaticStringViewTest, simple_usage) { static_assert(std::same_as<decltype(value),StaticStringView>); auto a_ref = value.ref(); auto a_view = value.view(); - static_assert(std::same_as<decltype(a_ref),vespalib::stringref>); + static_assert(std::same_as<decltype(a_ref),std::string_view>); static_assert(std::same_as<decltype(a_view),std::string_view>); - vespalib::stringref ref = value; + std::string_view ref = value; std::string_view view = value; EXPECT_EQ(a_ref, expect); EXPECT_EQ(a_view, expect_std); @@ -30,5 +30,3 @@ TEST(StaticStringViewTest, with_null_byte) { std::string expect("foo\0bar", 7); EXPECT_EQ(value.view(), expect); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/util/string_escape/CMakeLists.txt b/vespalib/src/tests/util/string_escape/CMakeLists.txt deleted file mode 100644 index 86885fc66ef..00000000000 --- a/vespalib/src/tests/util/string_escape/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_util_string_escape_test_app TEST - SOURCES - string_escape_test.cpp - DEPENDS - vespalib - GTest::GTest -) -vespa_add_test(NAME vespalib_util_string_escape_test_app COMMAND vespalib_util_string_escape_test_app) diff --git a/vespalib/src/tests/util/string_escape/string_escape_test.cpp b/vespalib/src/tests/util/string_escape_test.cpp index 313fc5eac60..aba139cd74a 100644 --- a/vespalib/src/tests/util/string_escape/string_escape_test.cpp +++ b/vespalib/src/tests/util/string_escape_test.cpp @@ -19,7 +19,7 @@ TEST(StringEscapeTest, xml_attribute_regular_chars_are_not_escaped) { TEST(StringEscapeTest, control_characters_are_escaped_in_attributes) { EXPECT_EQ(xml_attribute_escaped("\n"), " "); EXPECT_EQ(xml_attribute_escaped("\r"), " "); - EXPECT_EQ(xml_attribute_escaped(stringref("\x00", 1)), "�"); // Can't just invoke strlen with null byte :) + EXPECT_EQ(xml_attribute_escaped(std::string_view("\x00", 1)), "�"); // Can't just invoke strlen with null byte :) EXPECT_EQ(xml_attribute_escaped("\x1f"), ""); } @@ -37,8 +37,6 @@ TEST(StringEscapeTest, xml_content_regular_chars_are_not_escaped) { TEST(StringEscapeTest, control_characters_are_escaped_in_content) { EXPECT_EQ(xml_content_escaped("\r"), " "); - EXPECT_EQ(xml_content_escaped(stringref("\x00", 1)), "�"); + EXPECT_EQ(xml_content_escaped(std::string_view("\x00", 1)), "�"); EXPECT_EQ(xml_content_escaped("\x1f"), ""); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/util/time_test.cpp index e86d712e64c..7adbab21cbc 100644 --- a/vespalib/src/tests/time/time_test.cpp +++ b/vespalib/src/tests/util/time_test.cpp @@ -104,5 +104,3 @@ TEST(TimeTest, saturated_add_with_overflow) { EXPECT_EQ(saturated_add(future, duration::max()), steady_time::max()); EXPECT_EQ(saturated_add(past, duration::min()), steady_time::min()); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/typify/typify_test.cpp b/vespalib/src/tests/util/typify_test.cpp index 38cbf06a6ec..c463731a701 100644 --- a/vespalib/src/tests/typify/typify_test.cpp +++ b/vespalib/src/tests/util/typify_test.cpp @@ -120,5 +120,3 @@ TEST(TypifyTest, typify_invoke_can_return_object_reference) { EXPECT_NE(&s1, &s2); EXPECT_EQ(&s2, &s3); } - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/xmlserializable/xmlserializabletest.cpp b/vespalib/src/tests/util/xmlserializabletest.cpp index 3a6b933491a..f7ceec236e7 100644 --- a/vespalib/src/tests/xmlserializable/xmlserializabletest.cpp +++ b/vespalib/src/tests/util/xmlserializabletest.cpp @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/gtest/gtest.h> namespace vespalib { @@ -132,5 +132,3 @@ TEST(XmlSerializableTest, test_indent) } } // vespalib - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/tests/xmlserializable/.gitignore b/vespalib/src/tests/xmlserializable/.gitignore deleted file mode 100644 index 8573da1cd93..00000000000 --- a/vespalib/src/tests/xmlserializable/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*_test -.depend -Makefile -vespalib_xmlserializable_test_app diff --git a/vespalib/src/tests/xmlserializable/CMakeLists.txt b/vespalib/src/tests/xmlserializable/CMakeLists.txt deleted file mode 100644 index 4bd28a668a0..00000000000 --- a/vespalib/src/tests/xmlserializable/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_xmlserializable_test_app TEST - SOURCES - xmlserializabletest.cpp - DEPENDS - vespalib - GTest::gtest -) -vespa_add_test(NAME vespalib_xmlserializable_test_app COMMAND vespalib_xmlserializable_test_app) diff --git a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.hpp b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.hpp index fcc086fe411..0de5fa83728 100644 --- a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.hpp @@ -397,7 +397,7 @@ toString(const BTreeNode * node) const } vespalib::asciistream ss; if (node->isLeaf()) { - const LeafNodeType * lnode = static_cast<const LeafNodeType *>(node); + const auto * lnode = static_cast<const LeafNodeType *>(node); ss << "L: keys(" << lnode->validSlots() << ")["; for (uint32_t i = 0; i < lnode->validSlots(); ++i) { if (i > 0) ss << ","; @@ -405,8 +405,7 @@ toString(const BTreeNode * node) const } ss << "]"; } else { - const InternalNodeType * inode = - static_cast<const InternalNodeType *>(node); + const auto * inode = static_cast<const InternalNodeType *>(node); ss << "I: validLeaves(" << inode->validLeaves() << "), keys(" << inode->validSlots() << ")["; for (uint32_t i = 0; i < inode->validSlots(); ++i) { diff --git a/vespalib/src/vespa/vespalib/btree/btreeroot.hpp b/vespalib/src/vespa/vespalib/btree/btreeroot.hpp index 5acd83e944b..7d31d8704da 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeroot.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeroot.hpp @@ -20,21 +20,19 @@ BTreeRootT<KeyT, DataT, AggrT, CompareT, TraitsT>:: toString(BTreeNode::Ref node, const NodeAllocatorType &allocator) const { + vespalib::asciistream ss; if (allocator.isLeafRef(node)) { - vespalib::asciistream ss; ss << "{" << allocator.toString(node) << "}"; - return ss.str(); } else { const InternalNodeType * inode = allocator.mapInternalRef(node); - vespalib::asciistream ss; ss << "{" << allocator.toString(inode) << ",children(" << inode->validSlots() << ")["; for (size_t i = 0; i < inode->validSlots(); ++i) { if (i > 0) ss << ","; ss << "c[" << i << "]" << toString(inode->getChild(i), allocator); } ss << "]}"; - return ss.str(); } + return ss.str(); } template <typename KeyT, typename DataT, typename AggrT, typename CompareT, diff --git a/vespalib/src/vespa/vespalib/component/version.cpp b/vespalib/src/vespa/vespalib/component/version.cpp index 2112993e9d7..d9833ddbf54 100644 --- a/vespalib/src/vespa/vespalib/component/version.cpp +++ b/vespalib/src/vespa/vespalib/component/version.cpp @@ -34,7 +34,7 @@ Version::initialize() } else if (_major > 0) { buf << _major; } - _stringValue = buf.str(); + _stringValue = buf.view(); if ((_major < 0) || (_minor < 0) || (_micro < 0) || !_qualifier.empty()) { verifySanity(); } @@ -63,8 +63,8 @@ Version::verifySanity() } // Precondition: input.empty() == false -static int parseInteger(stringref input) __attribute__((noinline)); -static int parseInteger(stringref input) +static int parseInteger(std::string_view input) __attribute__((noinline)); +static int parseInteger(std::string_view input) { const char *s = input.data(); unsigned char firstDigit = s[0]; @@ -90,30 +90,30 @@ Version::Version(const string & versionString) _stringValue(versionString) { if ( ! versionString.empty()) { - stringref r(versionString.c_str(), versionString.size()); - stringref::size_type dot(r.find('.')); - stringref majorS(r.substr(0, dot)); + std::string_view r(versionString.c_str(), versionString.size()); + std::string_view::size_type dot(r.find('.')); + std::string_view majorS(r.substr(0, dot)); if ( !majorS.empty()) { _major = parseInteger(majorS); - if (dot == stringref::npos) return; + if (dot == std::string_view::npos) return; r = r.substr(dot + 1); dot = r.find('.'); - stringref minorS(r.substr(0, dot)); + std::string_view minorS(r.substr(0, dot)); if ( !minorS.empty()) { _minor = parseInteger(minorS); - if (dot == stringref::npos) return; + if (dot == std::string_view::npos) return; r = r.substr(dot + 1); dot = r.find('.'); - stringref microS(r.substr(0, dot)); + std::string_view microS(r.substr(0, dot)); if ( ! microS.empty()) { _micro = parseInteger(microS); - if (dot == stringref::npos) return; + if (dot == std::string_view::npos) return; r = r.substr(dot + 1); dot = r.find('.'); - if (dot == stringref::npos) { + if (dot == std::string_view::npos) { _qualifier = r; } else { throw IllegalArgumentException("too many dot-separated components in version string '" + versionString + "'"); diff --git a/vespalib/src/vespa/vespalib/component/versionspecification.cpp b/vespalib/src/vespa/vespalib/component/versionspecification.cpp index a9c65e5378b..8bfd82ec9fa 100644 --- a/vespalib/src/vespa/vespalib/component/versionspecification.cpp +++ b/vespalib/src/vespa/vespalib/component/versionspecification.cpp @@ -37,10 +37,10 @@ VersionSpecification::initialize() buf << "."; if (_micro == UNSPECIFIED) { buf << "*"; } else { buf << _micro; } - if (_qualifier != "") { + if (!_qualifier.empty()) { buf << "." << _qualifier; } - _stringValue = buf.str(); + _stringValue = buf.view(); if ((_major < UNSPECIFIED) || (_minor < UNSPECIFIED) || (_micro < UNSPECIFIED) || !_qualifier.empty()) { verifySanity(); @@ -60,7 +60,7 @@ VersionSpecification::verifySanity() if (_micro < UNSPECIFIED) throw IllegalArgumentException("Negative micro in " + _stringValue); - if (_qualifier != "") { + if (!_qualifier.empty()) { for (size_t i = 0; i < _qualifier.length(); i++) { unsigned char c = _qualifier[i]; if (! isalnum(c)) { @@ -70,10 +70,13 @@ VersionSpecification::verifySanity() } } -static int parseInteger(const VersionSpecification::string & input) __attribute__((noinline)); -static int parseInteger(const VersionSpecification::string & input) -{ - const char *s = input.c_str(); +namespace { + +int parseInteger(std::string_view input) __attribute__((noinline)); + +int parseInteger(std::string_view input) { + std::string zeroTerm(input); + const char *s = zeroTerm.c_str(); unsigned char firstDigit = s[0]; if (!isdigit(firstDigit)) throw IllegalArgumentException("integer must start with a digit"); @@ -88,6 +91,7 @@ static int parseInteger(const VersionSpecification::string & input) return ret; } +} VersionSpecification::VersionSpecification(const string & versionString) : _major(UNSPECIFIED), @@ -96,7 +100,7 @@ VersionSpecification::VersionSpecification(const string & versionString) _qualifier(), _stringValue() { - if (versionString != "") { + if (!versionString.empty()) { StringTokenizer components(versionString, ".", ""); // Split on dot if (components.size() > 0) @@ -140,7 +144,7 @@ VersionSpecification::compareTo(const VersionSpecification& other) const } bool -VersionSpecification::matches(int spec, int v) const +VersionSpecification::matches(int spec, int v) { if (spec == VersionSpecification::UNSPECIFIED) return true; return (spec == v); diff --git a/vespalib/src/vespa/vespalib/component/versionspecification.h b/vespalib/src/vespa/vespalib/component/versionspecification.h index d488745c39a..71d081a3f88 100644 --- a/vespalib/src/vespa/vespalib/component/versionspecification.h +++ b/vespalib/src/vespa/vespalib/component/versionspecification.h @@ -170,7 +170,7 @@ public: bool matches(const Version& version) const; private: - bool matches(int spec, int v) const; + static bool matches(int spec, int v) ; }; } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/crypto/openssl_crypto_impl.cpp b/vespalib/src/vespa/vespalib/crypto/openssl_crypto_impl.cpp index 6607a9f1652..9a41aec1ba6 100644 --- a/vespalib/src/vespa/vespalib/crypto/openssl_crypto_impl.cpp +++ b/vespalib/src/vespa/vespalib/crypto/openssl_crypto_impl.cpp @@ -177,7 +177,7 @@ void set_certificate_expires_from_now(::X509& cert, std::chrono::seconds valid_f } void -set_name_entry_if_non_empty(::X509_NAME& name, const char* field, vespalib::stringref entry) { +set_name_entry_if_non_empty(::X509_NAME& name, const char* field, std::string_view entry) { if (entry.empty()) { return; } diff --git a/vespalib/src/vespa/vespalib/crypto/x509_certificate.h b/vespalib/src/vespa/vespalib/crypto/x509_certificate.h index ccbee6fe94e..abb13dcd385 100644 --- a/vespalib/src/vespa/vespalib/crypto/x509_certificate.h +++ b/vespalib/src/vespa/vespalib/crypto/x509_certificate.h @@ -46,15 +46,15 @@ public: ~DistinguishedName(); // TODO could add rvalue overloads as well... - DistinguishedName& country(vespalib::stringref c) { _country = c; return *this; } - DistinguishedName& state(vespalib::stringref st) { _state = st; return *this; } - DistinguishedName& locality(vespalib::stringref l) { _locality = l; return *this; } - DistinguishedName& organization(vespalib::stringref o) { _organization = o; return *this; } - DistinguishedName& organizational_unit(vespalib::stringref ou) { + DistinguishedName& country(std::string_view c) { _country = c; return *this; } + DistinguishedName& state(std::string_view st) { _state = st; return *this; } + DistinguishedName& locality(std::string_view l) { _locality = l; return *this; } + DistinguishedName& organization(std::string_view o) { _organization = o; return *this; } + DistinguishedName& organizational_unit(std::string_view ou) { _organizational_unit = ou; return *this; } - DistinguishedName& add_common_name(vespalib::stringref cn) { + DistinguishedName& add_common_name(std::string_view cn) { _common_names.emplace_back(cn); return *this; } diff --git a/vespalib/src/vespa/vespalib/data/memory.h b/vespalib/src/vespa/vespalib/data/memory.h index c348b911a4b..7e917089770 100644 --- a/vespalib/src/vespa/vespalib/data/memory.h +++ b/vespalib/src/vespa/vespalib/data/memory.h @@ -22,10 +22,10 @@ struct Memory : data(str.data()), size(str.size()) {} Memory(const vespalib::string &str) noexcept : data(str.data()), size(str.size()) {} - Memory(vespalib::stringref str_ref) noexcept + Memory(std::string_view str_ref) noexcept : data(str_ref.data()), size(str_ref.size()) {} vespalib::string make_string() const; - vespalib::stringref make_stringref() const { return stringref(data, size); } + std::string_view make_stringview() const noexcept { return {data, size}; } bool operator == (const Memory &rhs) const noexcept { if (size != rhs.size) { return false; diff --git a/vespalib/src/vespa/vespalib/data/slime/inspector.cpp b/vespalib/src/vespa/vespalib/data/slime/inspector.cpp index 742c5ab0623..1999a056143 100644 --- a/vespalib/src/vespa/vespalib/data/slime/inspector.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/inspector.cpp @@ -7,7 +7,7 @@ namespace vespalib::slime { -using Path = std::vector<std::variant<size_t,vespalib::stringref>>; +using Path = std::vector<std::variant<size_t,std::string_view>>; using Hook = std::function<bool(const Path &, const Inspector &, const Inspector &)>; namespace { @@ -33,7 +33,7 @@ struct EqualObject : ObjectTraverser { : state(state_in), rhs(rhs_in) {} void field(const Memory &symbol, const Inspector &inspector) final { if (!state.failed) { - state.path.emplace_back(symbol.make_stringref()); + state.path.emplace_back(symbol.make_stringview()); state.check_equal(inspector, rhs[symbol]); state.path.pop_back(); } @@ -49,7 +49,7 @@ struct MissingFields : ObjectTraverser { if (!state.failed) { const Inspector &field = lhs[symbol]; if (!field.valid()) { - state.path.emplace_back(symbol.make_stringref()); + state.path.emplace_back(symbol.make_stringview()); state.mismatch(field, inspector); state.path.pop_back(); } diff --git a/vespalib/src/vespa/vespalib/data/slime/inspector.h b/vespalib/src/vespa/vespalib/data/slime/inspector.h index f035e179d95..a683a9fe3e8 100644 --- a/vespalib/src/vespa/vespalib/data/slime/inspector.h +++ b/vespalib/src/vespa/vespalib/data/slime/inspector.h @@ -46,7 +46,7 @@ std::ostream &operator<<(std::ostream &os, const Inspector &inspector); // check if two inspectors are equal // has support for allowing specific mismatches bool are_equal(const Inspector &a, const Inspector &b, - std::function<bool(const std::vector<std::variant<size_t,vespalib::stringref>> &path, + std::function<bool(const std::vector<std::variant<size_t,std::string_view>> &path, const Inspector &sub_a, const Inspector &sub_b)> allow_mismatch); } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/fuzzy/unicode_utils.cpp b/vespalib/src/vespa/vespalib/fuzzy/unicode_utils.cpp index 1d76198a048..12b926b0341 100644 --- a/vespalib/src/vespa/vespalib/fuzzy/unicode_utils.cpp +++ b/vespalib/src/vespa/vespalib/fuzzy/unicode_utils.cpp @@ -11,7 +11,7 @@ namespace { template <bool ToLowercase> std::vector<uint32_t> utf8_string_to_utf32_impl(std::string_view str) { - stringref ch_str(str.data(), str.size()); + std::string_view ch_str(str.data(), str.size()); Utf8Reader utf8_reader(ch_str); // TODO consider integrating simdutf library std::vector<uint32_t> u32ret; u32ret.reserve(str.size()); // Will over-allocate for all non-ASCII diff --git a/vespalib/src/vespa/vespalib/gtest/gtest.h b/vespalib/src/vespa/vespalib/gtest/gtest.h index 115d23dd925..c32b9ecfe9d 100644 --- a/vespalib/src/vespa/vespalib/gtest/gtest.h +++ b/vespalib/src/vespa/vespalib/gtest/gtest.h @@ -29,7 +29,7 @@ main(int argc, char* argv[]) \ TRY_BLOCK; \ FAIL() << "exception '" << MESSAGE << "' not thrown at all!"; \ } catch(EXCEPTION_TYPE& e) { \ - EXPECT_TRUE(contains(stringref(e.what()), stringref(MESSAGE))) << \ + EXPECT_TRUE(contains(std::string_view(e.what()), std::string_view(MESSAGE))) << \ " e.what(): " << e.what() << "\n"; \ } catch(...) { \ FAIL() << "wrong exception type thrown"; \ diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp index 4fab876ef68..691e054ea05 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.cpp +++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp @@ -22,7 +22,7 @@ namespace vespalib { namespace { FileInfo::UP -processStat(struct stat& filestats, bool result, stringref path) { +processStat(struct stat& filestats, bool result, std::string_view path) { FileInfo::UP resval; if (result) { resval = std::make_unique<FileInfo>(); @@ -33,7 +33,7 @@ processStat(struct stat& filestats, bool result, stringref path) { asciistream ost; ost << "An IO error occured while statting '" << path << "'. " << "errno(" << errno << "): " << getErrorString(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); + throw IoException(ost.view(), IoException::getErrorType(errno), VESPA_STRLOC); } LOG(debug, "stat(%s): Existed? %s, Plain file? %s, Directory? %s, Size: %" PRIu64, string(path).c_str(), @@ -52,7 +52,7 @@ safeStrerror(int errnum) } -File::File(stringref filename) +File::File(std::string_view filename) : _fd(-1), _filename(filename) { } @@ -102,7 +102,7 @@ File::open(int flags, bool autoCreateDirectories) { asciistream ost; ost << "open(" << _filename << ", 0x" << hex << flags << dec << "): Failed, errno(" << errno << "): " << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); + throw IoException(ost.view(), IoException::getErrorType(errno), VESPA_STRLOC); } if (_fd != -1) close(); _fd = fd; @@ -137,7 +137,7 @@ File::resize(off_t size) if (ftruncate(_fd, size) != 0) { asciistream ost; ost << "resize(" << _filename << ", " << size << "): Failed, errno(" << errno << "): " << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); + throw IoException(ost.view(), IoException::getErrorType(errno), VESPA_STRLOC); } LOG(debug, "resize(%s): Resized to %" PRIu64 " bytes.", _filename.c_str(), size); } @@ -162,7 +162,7 @@ File::write(const void *buf, size_t bufsize, off_t offset) asciistream ost; ost << "write(" << _fd << ", " << buf << ", " << left << ", " << offset << "), Failed, errno(" << errno << "): " << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); + throw IoException(ost.view(), IoException::getErrorType(errno), VESPA_STRLOC); } } return bufsize; @@ -188,7 +188,7 @@ File::read(void *buf, size_t bufsize, off_t offset) const asciistream ost; ost << "read(" << _fd << ", " << buf << ", " << remaining << ", " << offset << "): Failed, errno(" << errno << "): " << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); + throw IoException(ost.view(), IoException::getErrorType(errno), VESPA_STRLOC); } } return bufsize - remaining; @@ -217,7 +217,7 @@ File::readAll() const } vespalib::string -File::readAll(vespalib::stringref path) +File::readAll(std::string_view path) { File file(path); file.open(File::READONLY); @@ -240,7 +240,7 @@ File::sync() } void -File::sync(vespalib::stringref path) +File::sync(std::string_view path) { File file(path); file.open(READONLY); @@ -298,7 +298,7 @@ listDirectory(const string & path) return result; } -string dirname(stringref name) +string dirname(std::string_view name) { size_t found = name.rfind('/'); if (found == string::npos) { @@ -306,14 +306,15 @@ string dirname(stringref name) } else if (found == 0) { return string("/"); } else { - return name.substr(0, found); + return string(name.substr(0, found)); } } namespace { -void addStat(asciistream &os, const string & name) +void addStat(asciistream &os, std::string_view name_view) { + std::string name(name_view); struct ::stat filestat; memset(&filestat, '\0', sizeof(filestat)); int statres = ::stat(name.c_str(), &filestat); @@ -336,7 +337,7 @@ void addStat(asciistream &os, const string & name) } string -getOpenErrorString(const int osError, stringref filename) +getOpenErrorString(const int osError, std::string_view filename) { asciistream os; string dirName(dirname(filename)); diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h index 94926eb6681..a2735698cc0 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.h +++ b/vespalib/src/vespa/vespalib/io/fileutil.h @@ -76,7 +76,7 @@ public: enum Flag { READONLY = 1, CREATE = 2, TRUNC = 8 }; /** Create a file instance, without opening the file. */ - File(stringref filename); + File(std::string_view filename); /** Closes the file if not instructed to do otherwise. */ ~File(); @@ -154,7 +154,7 @@ public: * @throw IoException If we failed to read from file. * @return The content of the file. */ - static string readAll(stringref path); + static string readAll(std::string_view path); /** * Sync file or directory. @@ -164,7 +164,7 @@ public: * * @throw IoException If we failed to sync the file. */ - static void sync(stringref path); + static void sync(std::string_view path); bool close(); bool unlink(); @@ -175,7 +175,7 @@ public: */ using DirectoryList = std::vector<string>; extern DirectoryList listDirectory(const string & path); -string dirname(stringref name); -string getOpenErrorString(const int osError, stringref name); +string dirname(std::string_view name); +string getOpenErrorString(const int osError, std::string_view name); } // vespalib diff --git a/vespalib/src/vespa/vespalib/metrics/name_collection.cpp b/vespalib/src/vespa/vespalib/metrics/name_collection.cpp index eb2189ae32c..cf7b2ed480b 100644 --- a/vespalib/src/vespa/vespalib/metrics/name_collection.cpp +++ b/vespalib/src/vespa/vespalib/metrics/name_collection.cpp @@ -27,13 +27,13 @@ NameCollection::lookup(size_t id) const } size_t -NameCollection::resolve(const vespalib::string& name) +NameCollection::resolve(std::string_view name) { Guard guard(_lock); size_t nextId = _names_by_id.size(); auto iter_check = _names.emplace(name, nextId); if (iter_check.second) { - _names_by_id.push_back(iter_check.first); + _names_by_id.emplace_back(iter_check.first); } return iter_check.first->second; } diff --git a/vespalib/src/vespa/vespalib/metrics/name_collection.h b/vespalib/src/vespa/vespalib/metrics/name_collection.h index 7c9e1b1c652..faa8a88eae6 100644 --- a/vespalib/src/vespa/vespalib/metrics/name_collection.h +++ b/vespalib/src/vespa/vespalib/metrics/name_collection.h @@ -17,7 +17,7 @@ private: std::vector<Map::const_iterator> _names_by_id; public: const vespalib::string &lookup(size_t id) const; - size_t resolve(const vespalib::string& name); + size_t resolve(std::string_view name); size_t size() const; NameCollection(); diff --git a/vespalib/src/vespa/vespalib/metrics/prometheus_formatter.cpp b/vespalib/src/vespa/vespalib/metrics/prometheus_formatter.cpp index 4baa2216206..2de3ea7d442 100644 --- a/vespalib/src/vespa/vespalib/metrics/prometheus_formatter.cpp +++ b/vespalib/src/vespa/vespalib/metrics/prometheus_formatter.cpp @@ -13,7 +13,7 @@ namespace { return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_'); } -void emit_prometheus_name(asciistream& out, stringref name) { +void emit_prometheus_name(asciistream& out, std::string_view name) { for (char ch : name) { if (valid_prometheus_char(ch)) [[likely]] { out << ch; @@ -23,7 +23,7 @@ void emit_prometheus_name(asciistream& out, stringref name) { } } -void emit_label_value(asciistream& out, stringref value) { +void emit_label_value(asciistream& out, std::string_view value) { for (char ch : value) { if (ch == '\\') { out << "\\\\"; @@ -78,13 +78,15 @@ PrometheusFormatter::PrometheusFormatter(const vespalib::metrics::Snapshot& snap PrometheusFormatter::~PrometheusFormatter() = default; -void PrometheusFormatter::emit_counter(asciistream& out, const CounterSnapshot& cs) const { +void +PrometheusFormatter::emit_counter(asciistream& out, const CounterSnapshot& cs) const { emit_prometheus_name(out, cs.name()); emit_point_as_labels(out, cs.point()); out << ' ' << cs.count() << ' ' << _timestamp_str << '\n'; } -const char* PrometheusFormatter::sub_metric_type_str(SubMetric m) noexcept { +const char* +PrometheusFormatter::sub_metric_type_str(SubMetric m) noexcept { switch (m) { case SubMetric::Count: return "count"; case SubMetric::Sum: return "sum"; @@ -94,7 +96,8 @@ const char* PrometheusFormatter::sub_metric_type_str(SubMetric m) noexcept { abort(); } -void PrometheusFormatter::emit_gauge(asciistream& out, const GaugeSnapshot& gs, SubMetric m) const { +void +PrometheusFormatter::emit_gauge(asciistream& out, const GaugeSnapshot& gs, SubMetric m) const { emit_prometheus_name(out, gs.name()); out << '_' << sub_metric_type_str(m); emit_point_as_labels(out, gs.point()); @@ -108,7 +111,8 @@ void PrometheusFormatter::emit_gauge(asciistream& out, const GaugeSnapshot& gs, out << ' ' << _timestamp_str << '\n'; } -void PrometheusFormatter::emit_counters(vespalib::asciistream& out) const { +void +PrometheusFormatter::emit_counters(vespalib::asciistream& out) const { std::vector<const CounterSnapshot*> ordered_counters; ordered_counters.reserve(_snapshot.counters().size()); for (const auto& cs : _snapshot.counters()) { @@ -122,7 +126,8 @@ void PrometheusFormatter::emit_counters(vespalib::asciistream& out) const { } } -void PrometheusFormatter::emit_gauges(vespalib::asciistream& out) const { +void +PrometheusFormatter::emit_gauges(vespalib::asciistream& out) const { std::vector<std::pair<const GaugeSnapshot*, SubMetric>> ordered_gauges; ordered_gauges.reserve(_snapshot.gauges().size() * NumSubMetrics); for (const auto& gs : _snapshot.gauges()) { @@ -143,7 +148,8 @@ void PrometheusFormatter::emit_gauges(vespalib::asciistream& out) const { } } -vespalib::string PrometheusFormatter::as_text_formatted() const { +vespalib::string +PrometheusFormatter::as_text_formatted() const { asciistream out; emit_counters(out); emit_gauges(out); diff --git a/vespalib/src/vespa/vespalib/net/http/json_get_handler.h b/vespalib/src/vespa/vespalib/net/http/json_get_handler.h index 43793dbf1d8..179fb8d5e37 100644 --- a/vespalib/src/vespa/vespalib/net/http/json_get_handler.h +++ b/vespalib/src/vespa/vespalib/net/http/json_get_handler.h @@ -29,21 +29,21 @@ struct JsonGetHandler { [[nodiscard]] int status_code() const noexcept { return _status_code; } [[nodiscard]] bool ok() const noexcept { return _status_code == 200; } [[nodiscard]] bool failed() const noexcept { return _status_code != 200; } - [[nodiscard]] vespalib::stringref status_message() const noexcept { + [[nodiscard]] std::string_view status_message() const noexcept { if (_status_code == 200) { return "OK"; } else { return _status_or_payload; } } - [[nodiscard]] vespalib::stringref payload() const noexcept { + [[nodiscard]] std::string_view payload() const noexcept { if (_status_code == 200) { return _status_or_payload; } else { return {}; } } - [[nodiscard]] vespalib::stringref content_type() const noexcept { + [[nodiscard]] std::string_view content_type() const noexcept { if (_content_type_override.empty()) { return "application/json"; } else { diff --git a/vespalib/src/vespa/vespalib/net/http/json_handler_repo.cpp b/vespalib/src/vespa/vespalib/net/http/json_handler_repo.cpp index fa55908936c..5c7ad85c425 100644 --- a/vespalib/src/vespa/vespalib/net/http/json_handler_repo.cpp +++ b/vespalib/src/vespa/vespalib/net/http/json_handler_repo.cpp @@ -18,7 +18,7 @@ void remove_seq(T &collection, size_t seq) { } // namespace vespalib::<unnamed> size_t -JsonHandlerRepo::State::bind(vespalib::stringref path_prefix, +JsonHandlerRepo::State::bind(std::string_view path_prefix, const JsonGetHandler &get_handler) { std::lock_guard<std::mutex> guard(lock); @@ -29,7 +29,7 @@ JsonHandlerRepo::State::bind(vespalib::stringref path_prefix, } size_t -JsonHandlerRepo::State::add_root_resource(vespalib::stringref path) +JsonHandlerRepo::State::add_root_resource(std::string_view path) { std::lock_guard<std::mutex> guard(lock); size_t my_seq = ++seq; @@ -51,14 +51,14 @@ JsonHandlerRepo::JsonHandlerRepo() {} JsonHandlerRepo::~JsonHandlerRepo() = default; JsonHandlerRepo::Token::UP -JsonHandlerRepo::bind(vespalib::stringref path_prefix, +JsonHandlerRepo::bind(std::string_view path_prefix, const JsonGetHandler &get_handler) { return std::make_unique<Unbinder>(_state, _state->bind(path_prefix, get_handler)); } JsonHandlerRepo::Token::UP -JsonHandlerRepo::add_root_resource(vespalib::stringref path) +JsonHandlerRepo::add_root_resource(std::string_view path) { return std::make_unique<Unbinder>(_state, _state->add_root_resource(path)); } diff --git a/vespalib/src/vespa/vespalib/net/http/json_handler_repo.h b/vespalib/src/vespa/vespalib/net/http/json_handler_repo.h index 1e1ba6bf76d..c099be92213 100644 --- a/vespalib/src/vespa/vespalib/net/http/json_handler_repo.h +++ b/vespalib/src/vespa/vespalib/net/http/json_handler_repo.h @@ -34,7 +34,7 @@ private: vespalib::string path_prefix; const JsonGetHandler *handler; Hook(size_t seq_in, - vespalib::stringref prefix_in, + std::string_view prefix_in, const JsonGetHandler &handler_in) noexcept : seq(seq_in), path_prefix(prefix_in), handler(&handler_in) {} bool operator <(const Hook &rhs) const { @@ -48,7 +48,7 @@ private: struct Resource { size_t seq; vespalib::string path; - Resource(size_t seq_in, vespalib::stringref path_in) noexcept + Resource(size_t seq_in, std::string_view path_in) noexcept : seq(seq_in), path(path_in) {} }; @@ -59,9 +59,9 @@ private: std::vector<Hook> hooks; std::vector<Resource> root_resources; State() noexcept : lock(), seq(0), hooks(), root_resources() {} - size_t bind(vespalib::stringref path_prefix, + size_t bind(std::string_view path_prefix, const JsonGetHandler &get_handler); - size_t add_root_resource(vespalib::stringref path); + size_t add_root_resource(std::string_view path); void unbind(size_t my_seq); }; @@ -80,8 +80,8 @@ private: public: JsonHandlerRepo(); ~JsonHandlerRepo() override; - Token::UP bind(vespalib::stringref path_prefix, const JsonGetHandler &get_handler); - Token::UP add_root_resource(vespalib::stringref path); + Token::UP bind(std::string_view path_prefix, const JsonGetHandler &get_handler); + Token::UP add_root_resource(std::string_view path); [[nodiscard]] std::vector<vespalib::string> get_root_resources() const; [[nodiscard]] Response get(const vespalib::string &host, const vespalib::string &path, const std::map<vespalib::string,vespalib::string> ¶ms, diff --git a/vespalib/src/vespa/vespalib/net/http/slime_explorer.cpp b/vespalib/src/vespa/vespalib/net/http/slime_explorer.cpp index d1276f25443..17ba76a742b 100644 --- a/vespalib/src/vespa/vespalib/net/http/slime_explorer.cpp +++ b/vespalib/src/vespa/vespalib/net/http/slime_explorer.cpp @@ -49,7 +49,7 @@ SlimeExplorer::get_children_names() const } std::unique_ptr<StateExplorer> -SlimeExplorer::get_child(vespalib::stringref name) const +SlimeExplorer::get_child(std::string_view name) const { slime::Inspector &child = _self[name]; if (!child.valid()) { diff --git a/vespalib/src/vespa/vespalib/net/http/slime_explorer.h b/vespalib/src/vespa/vespalib/net/http/slime_explorer.h index 8e99be58b31..32444fea51c 100644 --- a/vespalib/src/vespa/vespalib/net/http/slime_explorer.h +++ b/vespalib/src/vespa/vespalib/net/http/slime_explorer.h @@ -24,7 +24,7 @@ public: SlimeExplorer(const slime::Inspector &self) : _self(self) {} virtual void get_state(const slime::Inserter &inserter, bool full) const override; virtual std::vector<vespalib::string> get_children_names() const override; - virtual std::unique_ptr<StateExplorer> get_child(vespalib::stringref name) const override; + virtual std::unique_ptr<StateExplorer> get_child(std::string_view name) const override; }; } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/net/http/state_api.cpp b/vespalib/src/vespa/vespalib/net/http/state_api.cpp index 31d0010d72d..f51fcc9a034 100644 --- a/vespalib/src/vespa/vespalib/net/http/state_api.cpp +++ b/vespalib/src/vespa/vespalib/net/http/state_api.cpp @@ -15,7 +15,7 @@ namespace { struct ConfigRenderer : ComponentConfigProducer::Consumer { JSONStringer &json; - ConfigRenderer(JSONStringer &j) : json(j) {} + explicit ConfigRenderer(JSONStringer &j) : json(j) {} void add(const ComponentConfigProducer::Config &config) override { json.appendKey(config.name); json.beginObject(); @@ -59,12 +59,12 @@ void build_health_status(JSONStringer &json, const HealthProducer &healthProduce } vespalib::string get_param(const std::map<vespalib::string,vespalib::string> ¶ms, - vespalib::stringref param_name, - vespalib::stringref default_value) + std::string_view param_name, + std::string_view default_value) { - auto maybe_value = params.find(param_name); + auto maybe_value = params.find(std::string(param_name)); if (maybe_value == params.end()) { - return default_value; + return vespalib::string(default_value); } return maybe_value->second; } @@ -89,7 +89,7 @@ vespalib::string respond_root(const JsonHandlerRepo &repo, const vespalib::strin } json.endArray(); json.endObject(); - return json.toString(); + return json.str(); } vespalib::string respond_health(const HealthProducer &healthProducer) { @@ -97,7 +97,7 @@ vespalib::string respond_health(const HealthProducer &healthProducer) { json.beginObject(); build_health_status(json, healthProducer); json.endObject(); - return json.toString(); + return json.str(); } vespalib::string respond_json_metrics(const vespalib::string &consumer, @@ -115,7 +115,7 @@ vespalib::string respond_json_metrics(const vespalib::string &consumer, } } json.endObject(); - return json.toString(); + return json.str(); } JsonGetHandler::Response cap_check_and_respond_metrics( @@ -151,7 +151,7 @@ vespalib::string respond_config(ComponentConfigProducer &componentConfigProducer json.endObject(); } json.endObject(); - return json.toString(); + return json.str(); } JsonGetHandler::Response cap_checked(const net::ConnectionAuthContext &auth_ctx, diff --git a/vespalib/src/vespa/vespalib/net/http/state_explorer.cpp b/vespalib/src/vespa/vespalib/net/http/state_explorer.cpp index 612615e9d6f..dc2934a3b35 100644 --- a/vespalib/src/vespa/vespalib/net/http/state_explorer.cpp +++ b/vespalib/src/vespa/vespalib/net/http/state_explorer.cpp @@ -11,7 +11,7 @@ StateExplorer::get_children_names() const } std::unique_ptr<StateExplorer> -StateExplorer::get_child(vespalib::stringref) const +StateExplorer::get_child(std::string_view) const { return std::unique_ptr<StateExplorer>(nullptr); } diff --git a/vespalib/src/vespa/vespalib/net/http/state_explorer.h b/vespalib/src/vespa/vespalib/net/http/state_explorer.h index aa836160875..f8168043ea8 100644 --- a/vespalib/src/vespa/vespalib/net/http/state_explorer.h +++ b/vespalib/src/vespa/vespalib/net/http/state_explorer.h @@ -15,7 +15,7 @@ namespace vespalib { struct StateExplorer { virtual void get_state(const slime::Inserter &inserter, bool full) const = 0; virtual std::vector<vespalib::string> get_children_names() const; - virtual std::unique_ptr<StateExplorer> get_child(vespalib::stringref name) const; + virtual std::unique_ptr<StateExplorer> get_child(std::string_view name) const; virtual ~StateExplorer(); }; diff --git a/vespalib/src/vespa/vespalib/net/tls/capability.cpp b/vespalib/src/vespa/vespalib/net/tls/capability.cpp index 1e1d144549d..d48383a3784 100644 --- a/vespalib/src/vespa/vespalib/net/tls/capability.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/capability.cpp @@ -55,8 +55,7 @@ std::string_view Capability::name() const noexcept { string Capability::to_string() const { asciistream os; - // TODO asciistream should be made std::string_view-aware - os << "Capability(" << stringref(name().data(), name().length()) << ')'; + os << "Capability(" << name() << ')'; return os.str(); } diff --git a/vespalib/src/vespa/vespalib/net/tls/capability_set.cpp b/vespalib/src/vespa/vespalib/net/tls/capability_set.cpp index c8635878b14..9e39e03edc5 100644 --- a/vespalib/src/vespa/vespalib/net/tls/capability_set.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/capability_set.cpp @@ -18,7 +18,7 @@ string CapabilitySet::to_string() const { emit_comma = true; } // TODO let asciistream and std::string_view play along - os << stringref(cap.name().data(), cap.name().size()); + os << std::string_view(cap.name().data(), cap.name().size()); }); os << "})"; return os.str(); diff --git a/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.cpp b/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.cpp index 5d863262066..e04d7070bd4 100644 --- a/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.cpp @@ -7,8 +7,8 @@ namespace vespalib::net::tls { -using vespalib::stringref; -using CipherMapType = std::unordered_map<stringref, stringref, vespalib::hash<stringref>>; +using std::string_view; +using CipherMapType = std::unordered_map<std::string_view, std::string_view, vespalib::hash<std::string_view>>; namespace { @@ -34,7 +34,7 @@ const CipherMapType& modern_cipher_suites_iana_to_openssl() { } // anon ns -const char* iana_cipher_suite_to_openssl(vespalib::stringref iana_name) { +const char* iana_cipher_suite_to_openssl(std::string_view iana_name) { const auto& ciphers = modern_cipher_suites_iana_to_openssl(); auto iter = ciphers.find(iana_name); return ((iter != ciphers.end()) ? iter->second.data() : nullptr); diff --git a/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.h b/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.h index e5fb5169cf0..31efa3c3134 100644 --- a/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.h +++ b/vespalib/src/vespa/vespalib/net/tls/impl/iana_cipher_map.h @@ -13,7 +13,7 @@ namespace vespalib::net::tls { * * Note that this only covers a very restricted subset of the existing IANA ciphers. */ -const char* iana_cipher_suite_to_openssl(vespalib::stringref iana_name); +const char* iana_cipher_suite_to_openssl(std::string_view iana_name); /** * Returns a vector of all IANA cipher suite names that we support internally. diff --git a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp index 2d89d9f80c7..20360930429 100644 --- a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp @@ -95,7 +95,7 @@ void ensure_openssl_initialized_once() { (void) openssl_resources; } -BioPtr bio_from_string(vespalib::stringref str) { +BioPtr bio_from_string(std::string_view str) { LOG_ASSERT(str.size() <= INT_MAX); #if (OPENSSL_VERSION_NUMBER >= 0x10002000L) BioPtr bio(::BIO_new_mem_buf(str.data(), static_cast<int>(str.size()))); @@ -234,7 +234,7 @@ OpenSslTlsContextImpl::~OpenSslTlsContextImpl() { } } -void OpenSslTlsContextImpl::add_certificate_authorities(vespalib::stringref ca_pem) { +void OpenSslTlsContextImpl::add_certificate_authorities(std::string_view ca_pem) { auto bio = bio_from_string(ca_pem); ::X509_STORE* cert_store = ::SSL_CTX_get_cert_store(_ctx.get()); // Internal pointer, not owned by us. while (true) { @@ -248,7 +248,7 @@ void OpenSslTlsContextImpl::add_certificate_authorities(vespalib::stringref ca_p } } -void OpenSslTlsContextImpl::add_certificate_chain(vespalib::stringref chain_pem) { +void OpenSslTlsContextImpl::add_certificate_chain(std::string_view chain_pem) { auto bio = bio_from_string(chain_pem); // First certificate in the chain is the node's own (trusted) certificate. auto own_cert = read_trusted_x509_from_bio(*bio); @@ -273,7 +273,7 @@ void OpenSslTlsContextImpl::add_certificate_chain(vespalib::stringref chain_pem) } } -void OpenSslTlsContextImpl::use_private_key(vespalib::stringref key_pem) { +void OpenSslTlsContextImpl::use_private_key(std::string_view key_pem) { auto bio = bio_from_string(key_pem); EvpPkeyPtr key(::PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, empty_passphrase())); if (!key) { diff --git a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h index d80913697a7..71b8054be14 100644 --- a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h +++ b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h @@ -32,9 +32,9 @@ public: AuthorizationMode authorization_mode() const noexcept override { return _authorization_mode; } private: // Note: single use per instance; does _not_ clear existing chain! - void add_certificate_authorities(stringref ca_pem); - void add_certificate_chain(stringref chain_pem); - void use_private_key(stringref key_pem); + void add_certificate_authorities(std::string_view ca_pem); + void add_certificate_chain(std::string_view chain_pem); + void use_private_key(std::string_view key_pem); void verify_private_key(); // Enable use of ephemeral key exchange (ECDHE), allowing forward secrecy. void enable_ephemeral_key_exchange(); diff --git a/vespalib/src/vespa/vespalib/net/tls/peer_credentials.cpp b/vespalib/src/vespa/vespalib/net/tls/peer_credentials.cpp index 9b903203202..5243b01bc11 100644 --- a/vespalib/src/vespa/vespalib/net/tls/peer_credentials.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/peer_credentials.cpp @@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& os, const PeerCredentials& creds) { } namespace { -void emit_comma_separated_string_list(asciistream& os, stringref title, +void emit_comma_separated_string_list(asciistream& os, std::string_view title, const std::vector<string>& strings, bool prefix_comma) { if (prefix_comma) { diff --git a/vespalib/src/vespa/vespalib/net/tls/peer_policies.cpp b/vespalib/src/vespa/vespalib/net/tls/peer_policies.cpp index ec024affe21..ab2316b9542 100644 --- a/vespalib/src/vespa/vespalib/net/tls/peer_policies.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/peer_policies.cpp @@ -34,7 +34,7 @@ is_regex_special_char(char c) noexcept { // Important: `delimiter` MUST NOT be a character that needs escaping within a regex [charset] template <bool SupportSingleCharMatch> std::string -char_delimited_glob_to_regex(vespalib::stringref glob, char delimiter) { +char_delimited_glob_to_regex(std::string_view glob, char delimiter) { std::string ret = "^"; ret.reserve(glob.size() + 2); // Note: we explicitly stop matching at a delimiter boundary. @@ -70,15 +70,15 @@ public: RegexHostMatchPattern& operator=(RegexHostMatchPattern&&) noexcept = default; - [[nodiscard]] static RegexHostMatchPattern from_dns_glob_pattern(vespalib::stringref glob_pattern) { + [[nodiscard]] static RegexHostMatchPattern from_dns_glob_pattern(std::string_view glob_pattern) { return RegexHostMatchPattern(char_delimited_glob_to_regex<true>(glob_pattern, '.')); } - [[nodiscard]] static RegexHostMatchPattern from_uri_glob_pattern(vespalib::stringref glob_pattern) { + [[nodiscard]] static RegexHostMatchPattern from_uri_glob_pattern(std::string_view glob_pattern) { return RegexHostMatchPattern(char_delimited_glob_to_regex<false>(glob_pattern, '/')); } - [[nodiscard]] bool matches(vespalib::stringref str) const noexcept override { + [[nodiscard]] bool matches(std::string_view str) const noexcept override { return _pattern_as_regex.full_match(std::string_view(str.data(), str.size())); } }; @@ -86,13 +86,13 @@ public: class ExactMatchPattern : public CredentialMatchPattern { vespalib::string _must_match_exactly; public: - explicit ExactMatchPattern(vespalib::stringref str_to_match) noexcept // vespalib::string ctors marked noexcept + explicit ExactMatchPattern(std::string_view str_to_match) noexcept // vespalib::string ctors marked noexcept : _must_match_exactly(str_to_match) { } ~ExactMatchPattern() override = default; - [[nodiscard]] bool matches(vespalib::stringref str) const noexcept override { + [[nodiscard]] bool matches(std::string_view str) const noexcept override { return (str == _must_match_exactly); } }; @@ -100,23 +100,23 @@ public: } // anon ns std::shared_ptr<const CredentialMatchPattern> -CredentialMatchPattern::create_from_dns_glob(vespalib::stringref glob_pattern) { +CredentialMatchPattern::create_from_dns_glob(std::string_view glob_pattern) { return std::make_shared<const RegexHostMatchPattern>(RegexHostMatchPattern::from_dns_glob_pattern(glob_pattern)); } std::shared_ptr<const CredentialMatchPattern> - CredentialMatchPattern::create_from_uri_glob(vespalib::stringref glob_pattern) { + CredentialMatchPattern::create_from_uri_glob(std::string_view glob_pattern) { return std::make_shared<const RegexHostMatchPattern>(RegexHostMatchPattern::from_uri_glob_pattern(glob_pattern)); } std::shared_ptr<const CredentialMatchPattern> -CredentialMatchPattern::create_exact_match(vespalib::stringref str) { +CredentialMatchPattern::create_exact_match(std::string_view str) { return std::make_shared<const ExactMatchPattern>(str); } -RequiredPeerCredential::RequiredPeerCredential(Field field, vespalib::string must_match_pattern) +RequiredPeerCredential::RequiredPeerCredential(Field field, std::string_view must_match_pattern) : _field(field), - _original_pattern(std::move(must_match_pattern)), + _original_pattern(must_match_pattern), _match_pattern(field == Field::SAN_URI ? CredentialMatchPattern::create_from_uri_glob(_original_pattern) : CredentialMatchPattern::create_from_dns_glob(_original_pattern)) { diff --git a/vespalib/src/vespa/vespalib/net/tls/peer_policies.h b/vespalib/src/vespa/vespalib/net/tls/peer_policies.h index e79a75ca20c..9756a328361 100644 --- a/vespalib/src/vespa/vespalib/net/tls/peer_policies.h +++ b/vespalib/src/vespa/vespalib/net/tls/peer_policies.h @@ -11,11 +11,11 @@ namespace vespalib::net::tls { struct CredentialMatchPattern { virtual ~CredentialMatchPattern() = default; - [[nodiscard]] virtual bool matches(vespalib::stringref str) const noexcept = 0; + [[nodiscard]] virtual bool matches(std::string_view str) const noexcept = 0; - static std::shared_ptr<const CredentialMatchPattern> create_from_dns_glob(vespalib::stringref glob_pattern); - static std::shared_ptr<const CredentialMatchPattern> create_from_uri_glob(vespalib::stringref glob_pattern); - static std::shared_ptr<const CredentialMatchPattern> create_exact_match(vespalib::stringref pattern); + static std::shared_ptr<const CredentialMatchPattern> create_from_dns_glob(std::string_view glob_pattern); + static std::shared_ptr<const CredentialMatchPattern> create_from_uri_glob(std::string_view glob_pattern); + static std::shared_ptr<const CredentialMatchPattern> create_exact_match(std::string_view pattern); }; class RequiredPeerCredential { @@ -29,7 +29,7 @@ private: std::shared_ptr<const CredentialMatchPattern> _match_pattern; public: RequiredPeerCredential() = default; - RequiredPeerCredential(Field field, vespalib::string must_match_pattern); + RequiredPeerCredential(Field field, std::string_view must_match_pattern); RequiredPeerCredential(const RequiredPeerCredential &) noexcept; RequiredPeerCredential & operator=(const RequiredPeerCredential &) = delete; RequiredPeerCredential(RequiredPeerCredential &&) noexcept; @@ -43,7 +43,7 @@ public: && (_original_pattern == rhs._original_pattern)); } - [[nodiscard]] bool matches(vespalib::stringref str) const noexcept { + [[nodiscard]] bool matches(std::string_view str) const noexcept { return (_match_pattern && _match_pattern->matches(str)); } diff --git a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h index 70de9292c76..ba08c8ebc9d 100644 --- a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h +++ b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h @@ -31,9 +31,9 @@ public: Params(Params&&) noexcept; Params& operator=(Params&&) noexcept; - Params& ca_certs_pem(vespalib::stringref pem) { _ca_certs_pem = pem; return *this; } - Params& cert_chain_pem(vespalib::stringref pem) { _cert_chain_pem = pem; return *this; } - Params& private_key_pem(vespalib::stringref pem) { _private_key_pem = pem; return *this; } + Params& ca_certs_pem(std::string_view pem) { _ca_certs_pem = pem; return *this; } + Params& cert_chain_pem(std::string_view pem) { _cert_chain_pem = pem; return *this; } + Params& private_key_pem(std::string_view pem) { _private_key_pem = pem; return *this; } Params& authorized_peers(AuthorizedPeers auth) { _authorized_peers = std::move(auth); return *this; } Params& accepted_ciphers(std::vector<vespalib::string> ciphers) { _accepted_ciphers = std::move(ciphers); diff --git a/vespalib/src/vespa/vespalib/net/tls/verification_result.cpp b/vespalib/src/vespa/vespalib/net/tls/verification_result.cpp index 99a5fe5a2e9..3b2abc4d5b1 100644 --- a/vespalib/src/vespa/vespalib/net/tls/verification_result.cpp +++ b/vespalib/src/vespa/vespalib/net/tls/verification_result.cpp @@ -57,7 +57,8 @@ std::ostream& operator<<(std::ostream& os, const VerificationResult& res) { return os; } -string to_string(const VerificationResult& res) { +string +to_string(const VerificationResult& res) { asciistream os; os << res; return os.str(); diff --git a/vespalib/src/vespa/vespalib/objects/asciiserializer.cpp b/vespalib/src/vespa/vespalib/objects/asciiserializer.cpp index a24e44bee40..2f599f484c3 100644 --- a/vespalib/src/vespa/vespalib/objects/asciiserializer.cpp +++ b/vespalib/src/vespa/vespalib/objects/asciiserializer.cpp @@ -39,7 +39,7 @@ AsciiSerializer &AsciiSerializer::put(double value) { return *this; } -AsciiSerializer &AsciiSerializer::put(stringref value) { +AsciiSerializer &AsciiSerializer::put(std::string_view value) { _stream << value; return *this; } diff --git a/vespalib/src/vespa/vespalib/objects/asciiserializer.h b/vespalib/src/vespa/vespalib/objects/asciiserializer.h index c7cc4ec0aa3..11cd5f80dd2 100644 --- a/vespalib/src/vespa/vespalib/objects/asciiserializer.h +++ b/vespalib/src/vespa/vespalib/objects/asciiserializer.h @@ -18,7 +18,7 @@ public: AsciiSerializer &put(uint64_t value) override; AsciiSerializer &put(float value) override; AsciiSerializer &put(double value) override; - AsciiSerializer &put(stringref val) override; + AsciiSerializer &put(std::string_view val) override; const asciistream &getStream() const { return _stream; } asciistream &getStream() { return _stream; } diff --git a/vespalib/src/vespa/vespalib/objects/nboserializer.cpp b/vespalib/src/vespa/vespalib/objects/nboserializer.cpp index 959a81c9a77..6b257de429c 100644 --- a/vespalib/src/vespa/vespalib/objects/nboserializer.cpp +++ b/vespalib/src/vespa/vespalib/objects/nboserializer.cpp @@ -43,7 +43,7 @@ NBOSerializer &NBOSerializer::put(double value) { return *this; } -NBOSerializer &NBOSerializer::put(stringref value) { +NBOSerializer &NBOSerializer::put(std::string_view value) { _stream << value; return *this; } diff --git a/vespalib/src/vespa/vespalib/objects/nboserializer.h b/vespalib/src/vespa/vespalib/objects/nboserializer.h index c0839bdc4b4..96e8fa8a074 100644 --- a/vespalib/src/vespa/vespalib/objects/nboserializer.h +++ b/vespalib/src/vespa/vespalib/objects/nboserializer.h @@ -18,7 +18,7 @@ public: NBOSerializer &put(uint64_t value) override; NBOSerializer &put(float value) override; NBOSerializer &put(double value) override; - NBOSerializer &put(stringref val) override; + NBOSerializer &put(std::string_view val) override; NBOSerializer &get(bool &value) override; NBOSerializer &get(uint8_t &value) override; diff --git a/vespalib/src/vespa/vespalib/objects/nbostream.h b/vespalib/src/vespa/vespalib/objects/nbostream.h index f66c261ae91..8302bbac123 100644 --- a/vespalib/src/vespa/vespalib/objects/nbostream.h +++ b/vespalib/src/vespa/vespalib/objects/nbostream.h @@ -74,7 +74,7 @@ public: return *this; } nbostream & operator << (const char * v) { uint32_t sz(strlen(v)); (*this) << sz; write(v, sz); return *this; } - nbostream & operator << (vespalib::stringref v) { uint32_t sz(v.size()); (*this) << sz; write(v.data(), sz); return *this; } + nbostream & operator << (std::string_view v) { uint32_t sz(v.size()); (*this) << sz; write(v.data(), sz); return *this; } nbostream & operator << (const vespalib::string & v) { uint32_t sz(v.size()); (*this) << sz; write(v.c_str(), sz); return *this; } nbostream & operator >> (vespalib::string & v) { uint32_t sz; (*this) >> sz; @@ -182,7 +182,7 @@ public: return readValue<uint32_t>() & 0x7fffffff; } } - void writeSmallString(vespalib::stringref value) { + void writeSmallString(std::string_view value) { putInt1_4Bytes(value.size()); write(value.data(), value.size()); } diff --git a/vespalib/src/vespa/vespalib/objects/object2slime.cpp b/vespalib/src/vespa/vespalib/objects/object2slime.cpp index 09c03e827db..718a46d35d8 100644 --- a/vespalib/src/vespa/vespalib/objects/object2slime.cpp +++ b/vespalib/src/vespa/vespalib/objects/object2slime.cpp @@ -17,7 +17,7 @@ Object2Slime::~Object2Slime() = default; //----------------------------------------------------------------------------- void -Object2Slime::openStruct(const vespalib::string &name, const vespalib::string &type) +Object2Slime::openStruct(std::string_view name, std::string_view type) { if (name.empty()) { _cursor.get().setString("[type]", type); @@ -38,31 +38,31 @@ Object2Slime::closeStruct() } void -Object2Slime::visitBool(const vespalib::string &name, bool value) +Object2Slime::visitBool(std::string_view name, bool value) { _cursor.get().setBool(name, value); } void -Object2Slime::visitInt(const vespalib::string &name, int64_t value) +Object2Slime::visitInt(std::string_view name, int64_t value) { _cursor.get().setLong(name, value); } void -Object2Slime::visitFloat(const vespalib::string &name, double value) +Object2Slime::visitFloat(std::string_view name, double value) { _cursor.get().setDouble(name, value); } void -Object2Slime::visitString(const vespalib::string &name, const vespalib::string &value) +Object2Slime::visitString(std::string_view name, std::string_view value) { _cursor.get().setString(name, value); } void -Object2Slime::visitNull(const vespalib::string &name) +Object2Slime::visitNull(std::string_view name) { _cursor.get().setNix(name); } diff --git a/vespalib/src/vespa/vespalib/objects/object2slime.h b/vespalib/src/vespa/vespalib/objects/object2slime.h index 327fe7b1c1a..27511269f83 100644 --- a/vespalib/src/vespa/vespalib/objects/object2slime.h +++ b/vespalib/src/vespa/vespalib/objects/object2slime.h @@ -21,16 +21,16 @@ private: std::vector<std::reference_wrapper<slime::Cursor>> _stack; public: - Object2Slime(slime::Cursor & cursor); - ~Object2Slime(); + explicit Object2Slime(slime::Cursor & cursor); + ~Object2Slime() override; - void openStruct(const vespalib::string &name, const vespalib::string &type) override; + void openStruct(std::string_view name, std::string_view type) override; void closeStruct() override; - void visitBool(const vespalib::string &name, bool value) override; - void visitInt(const vespalib::string &name, int64_t value) override; - void visitFloat(const vespalib::string &name, double value) override; - void visitString(const vespalib::string &name, const vespalib::string &value) override; - void visitNull(const vespalib::string &name) override; + void visitBool(std::string_view name, bool value) override; + void visitInt(std::string_view name, int64_t value) override; + void visitFloat(std::string_view name, double value) override; + void visitString(std::string_view name, std::string_view value) override; + void visitNull(std::string_view name) override; void visitNotImplemented() override; }; diff --git a/vespalib/src/vespa/vespalib/objects/objectdumper.cpp b/vespalib/src/vespa/vespalib/objects/objectdumper.cpp index 2287906fe0f..313e80d45a0 100644 --- a/vespalib/src/vespa/vespalib/objects/objectdumper.cpp +++ b/vespalib/src/vespa/vespalib/objects/objectdumper.cpp @@ -4,6 +4,8 @@ namespace vespalib { +using string = vespalib::string; + void ObjectDumper::addIndent() { @@ -11,11 +13,11 @@ ObjectDumper::addIndent() if (n < 0) { n = 0; } - _str.append(vespalib::string(n, ' ')); + _str.append(string(n, ' ')); } void -ObjectDumper::addLine(const vespalib::string &line) +ObjectDumper::addLine(const string &line) { addIndent(); _str.append(line); @@ -46,12 +48,12 @@ ObjectDumper::~ObjectDumper() = default; //----------------------------------------------------------------------------- void -ObjectDumper::openStruct(const vespalib::string &name, const vespalib::string &type) +ObjectDumper::openStruct(std::string_view name, std::string_view type) { if (name.empty()) { - addLine(make_string("%s {", type.c_str())); + addLine(type + " {"); } else { - addLine(make_string("%s: %s {", name.c_str(), type.c_str())); + addLine((string(name).append(": ").append(type).append(" {"))); } openScope(); } @@ -64,33 +66,33 @@ ObjectDumper::closeStruct() } void -ObjectDumper::visitBool(const vespalib::string &name, bool value) +ObjectDumper::visitBool(std::string_view name, bool value) { - addLine(make_string("%s: %s", name.c_str(), value? "true" : "false")); + addLine(string(name).append(value ? ": true" : ": false")); } void -ObjectDumper::visitInt(const vespalib::string &name, int64_t value) +ObjectDumper::visitInt(std::string_view name, int64_t value) { - addLine(make_string("%s: %" PRId64 "", name.c_str(), value)); + addLine(make_string("%s: %" PRId64 "", string(name).c_str(), value)); } void -ObjectDumper::visitFloat(const vespalib::string &name, double value) +ObjectDumper::visitFloat(std::string_view name, double value) { - addLine(make_string("%s: %g", name.c_str(), value)); + addLine(make_string("%s: %g", string(name).c_str(), value)); } void -ObjectDumper::visitString(const vespalib::string &name, const vespalib::string &value) +ObjectDumper::visitString(std::string_view name, std::string_view value) { - addLine(make_string("%s: '%s'", name.c_str(), value.c_str())); + addLine(string(name).append(": '").append(value).append('\'')); } void -ObjectDumper::visitNull(const vespalib::string &name) +ObjectDumper::visitNull(std::string_view name) { - addLine(make_string("%s: <NULL>", name.c_str())); + addLine(name + ": <NULL>"); } void diff --git a/vespalib/src/vespa/vespalib/objects/objectdumper.h b/vespalib/src/vespa/vespalib/objects/objectdumper.h index 1ab20345284..5e16a077d6b 100644 --- a/vespalib/src/vespa/vespalib/objects/objectdumper.h +++ b/vespalib/src/vespa/vespalib/objects/objectdumper.h @@ -48,8 +48,8 @@ public: * * @param indent indent size in number of spaces **/ - ObjectDumper(int indent = 4); - ~ObjectDumper(); + explicit ObjectDumper(int indent = 4); + ~ObjectDumper() override; /** * Obtain the created object string representation. This object @@ -58,15 +58,15 @@ public: * * @return object string representation **/ - vespalib::string toString() const { return _str; } + const vespalib::string & toString() const { return _str; } - void openStruct(const vespalib::string &name, const vespalib::string &type) override; + void openStruct(std::string_view name, std::string_view type) override; void closeStruct() override; - void visitBool(const vespalib::string &name, bool value) override; - void visitInt(const vespalib::string &name, int64_t value) override; - void visitFloat(const vespalib::string &name, double value) override; - void visitString(const vespalib::string &name, const vespalib::string &value) override; - void visitNull(const vespalib::string &name) override; + void visitBool(std::string_view name, bool value) override; + void visitInt(std::string_view name, int64_t value) override; + void visitFloat(std::string_view name, double value) override; + void visitString(std::string_view name, std::string_view value) override; + void visitNull(std::string_view name) override; void visitNotImplemented() override; }; diff --git a/vespalib/src/vespa/vespalib/objects/objectvisitor.h b/vespalib/src/vespa/vespalib/objects/objectvisitor.h index fe08d0010d7..c1af290c580 100644 --- a/vespalib/src/vespa/vespalib/objects/objectvisitor.h +++ b/vespalib/src/vespa/vespalib/objects/objectvisitor.h @@ -22,7 +22,7 @@ public: * @param name name of structure * @param type type of structure **/ - virtual void openStruct(const vespalib::string &name, const vespalib::string &type) = 0; + virtual void openStruct(std::string_view name, std::string_view type) = 0; /** * Close a (sub-)structure @@ -35,7 +35,7 @@ public: * @param name variable name * @param value variable value **/ - virtual void visitBool(const vespalib::string &name, bool value) = 0; + virtual void visitBool(std::string_view name, bool value) = 0; /** * Visit an integer value @@ -43,7 +43,7 @@ public: * @param name variable name * @param value variable value **/ - virtual void visitInt(const vespalib::string &name, int64_t value) = 0; + virtual void visitInt(std::string_view name, int64_t value) = 0; /** * Visit a floating-point value @@ -51,7 +51,7 @@ public: * @param name variable name * @param value variable value **/ - virtual void visitFloat(const vespalib::string &name, double value) = 0; + virtual void visitFloat(std::string_view name, double value) = 0; /** * Visit a string value @@ -59,7 +59,7 @@ public: * @param name variable name * @param value variable value **/ - virtual void visitString(const vespalib::string &name, const vespalib::string &value) = 0; + virtual void visitString(std::string_view name, std::string_view value) = 0; /** * Visit method used to indicate that an optional substructure is @@ -67,7 +67,7 @@ public: * * @param name variable name **/ - virtual void visitNull(const vespalib::string &name) = 0; + virtual void visitNull(std::string_view name) = 0; /** * Visit method invoked by the default implementation of member diff --git a/vespalib/src/vespa/vespalib/objects/serializer.h b/vespalib/src/vespa/vespalib/objects/serializer.h index 020b59fa926..5bacdcfbb59 100644 --- a/vespalib/src/vespa/vespalib/objects/serializer.h +++ b/vespalib/src/vespa/vespalib/objects/serializer.h @@ -20,7 +20,7 @@ public: virtual Serializer & put(uint64_t value) = 0; virtual Serializer & put(float value) = 0; virtual Serializer & put(double value) = 0; - virtual Serializer & put(stringref value) = 0; + virtual Serializer & put(std::string_view value) = 0; virtual Serializer & put(const Identifiable & value); virtual Serializer & put(int8_t value); @@ -39,7 +39,7 @@ public: Serializer & operator << (int64_t value) { return put(value); } Serializer & operator << (float value) { return put(value); } Serializer & operator << (double value) { return put(value); } - Serializer & operator << (stringref value) { return put(value); } + Serializer & operator << (std::string_view value) { return put(value); } template <typename T> Serializer & operator << (const std::vector<T> & v); }; diff --git a/vespalib/src/vespa/vespalib/objects/visit.cpp b/vespalib/src/vespa/vespalib/objects/visit.cpp index b7286a9817b..9493fc40bfe 100644 --- a/vespalib/src/vespa/vespalib/objects/visit.cpp +++ b/vespalib/src/vespa/vespalib/objects/visit.cpp @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "visit.hpp" -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable *obj) { - if (obj != 0) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::Identifiable *obj) { + if (obj != nullptr) { self.openStruct(name, obj->getClass().name()); obj->visitMembers(self); self.closeStruct(); @@ -11,82 +11,78 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const ve } } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable &obj) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::Identifiable &obj) { visit(self, name, &obj); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, bool value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, bool value) { self.visitBool(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, char value) +void visit(vespalib::ObjectVisitor &self, std::string_view name, char value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, signed char value) +void visit(vespalib::ObjectVisitor &self, std::string_view name, signed char value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned char value) +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned char value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, short value) +void visit(vespalib::ObjectVisitor &self, std::string_view name, short value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned short value) +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned short value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, int value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, int value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned int value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned int value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, long value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, long value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned long value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned long value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, long long value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, long long value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned long long value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned long long value) { self.visitInt(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, float value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, float value) { self.visitFloat(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, double value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, double value) { self.visitFloat(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::string &value) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, std::string_view value) { self.visitString(name, value); } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::string &value) { - self.visitString(name, value); -} - -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const char *value) { - if (value != 0) { - visit(self, name, vespalib::string(value)); +void visit(vespalib::ObjectVisitor &self, std::string_view name, const char *value) { + if (value != nullptr) { + visit(self, name, std::string_view(value)); } else { self.visitNull(name); } diff --git a/vespalib/src/vespa/vespalib/objects/visit.h b/vespalib/src/vespa/vespalib/objects/visit.h index 1fd426b5660..a9d2aa6eb75 100644 --- a/vespalib/src/vespa/vespalib/objects/visit.h +++ b/vespalib/src/vespa/vespalib/objects/visit.h @@ -8,22 +8,21 @@ namespace vespalib { class ObjectVisitor; } -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable *obj); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable &obj); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, bool value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, char value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, signed char value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned char value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, short value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned short value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, int value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned int value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, long value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned long value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, long long value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, unsigned long long value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, float value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, double value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::string &value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, vespalib::stringref value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const char *value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::Identifiable *obj); +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::Identifiable &obj); +void visit(vespalib::ObjectVisitor &self, std::string_view name, bool value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, char value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, signed char value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned char value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, short value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned short value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, int value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned int value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, long value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned long value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, long long value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, unsigned long long value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, float value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, double value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, std::string_view value); +void visit(vespalib::ObjectVisitor &self, std::string_view name, const char *value); diff --git a/vespalib/src/vespa/vespalib/objects/visit.hpp b/vespalib/src/vespa/vespalib/objects/visit.hpp index 7105bd7cfbb..1e28473d5da 100644 --- a/vespalib/src/vespa/vespalib/objects/visit.hpp +++ b/vespalib/src/vespa/vespalib/objects/visit.hpp @@ -8,7 +8,7 @@ #include "identifiable.hpp" template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::CloneablePtr<T> &ptr) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::CloneablePtr<T> &ptr) { if (ptr.get()) { visit(self, name, *ptr); } else { @@ -17,7 +17,7 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const ve } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::shared_ptr<T> &ptr) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const std::shared_ptr<T> &ptr) { if (ptr.get()) { visit(self, name, *ptr); } else { @@ -26,7 +26,7 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const st } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::unique_ptr<T> &ptr) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const std::unique_ptr<T> &ptr) { if (ptr.get()) { visit(self, name, *ptr); } else { @@ -35,17 +35,17 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const st } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiablePtr<T> &ptr) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::IdentifiablePtr<T> &ptr) { visit(self, name, ptr.get()); } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableSharedPtr<T> &ptr) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::IdentifiableSharedPtr<T> &ptr) { visit(self, name, ptr.get()); } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::vector<T> &list) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const std::vector<T> &list) { self.openStruct(name, "std::vector"); for (uint32_t i = 0; i < list.size(); ++i) { ::visit(self, vespalib::make_string("[%u]", i), list[i]); @@ -54,7 +54,7 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const st } template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Array<T> &list) { +void visit(vespalib::ObjectVisitor &self, std::string_view name, const vespalib::Array<T> &list) { self.openStruct(name, "vespalib::Array"); for (uint32_t i = 0; i < list.size(); ++i) { ::visit(self, vespalib::make_string("[%u]", i), list[i]); diff --git a/vespalib/src/vespa/vespalib/portal/http_connection.cpp b/vespalib/src/vespa/vespalib/portal/http_connection.cpp index 45cdbec0121..ded61d34f76 100644 --- a/vespalib/src/vespa/vespalib/portal/http_connection.cpp +++ b/vespalib/src/vespa/vespalib/portal/http_connection.cpp @@ -245,8 +245,8 @@ HttpConnection::handle_event(bool, bool) } void -HttpConnection::respond_with_content(vespalib::stringref content_type, - vespalib::stringref content) +HttpConnection::respond_with_content(std::string_view content_type, + std::string_view content) { { OutputWriter dst(_output, CHUNK_SIZE); @@ -265,7 +265,7 @@ HttpConnection::respond_with_content(vespalib::stringref content_type, } void -HttpConnection::respond_with_error(int code, vespalib::stringref msg) +HttpConnection::respond_with_error(int code, std::string_view msg) { { OutputWriter dst(_output, CHUNK_SIZE); diff --git a/vespalib/src/vespa/vespalib/portal/http_connection.h b/vespalib/src/vespa/vespalib/portal/http_connection.h index afcc780ef98..2af14c07fa3 100644 --- a/vespalib/src/vespa/vespalib/portal/http_connection.h +++ b/vespalib/src/vespa/vespalib/portal/http_connection.h @@ -53,9 +53,9 @@ public: // Precondition: handshake must have been completed const net::ConnectionAuthContext &auth_context() const noexcept { return *_auth_ctx; } - void respond_with_content(vespalib::stringref content_type, - vespalib::stringref content); - void respond_with_error(int code, const vespalib::stringref msg); + void respond_with_content(std::string_view content_type, + std::string_view content); + void respond_with_error(int code, const std::string_view msg); }; } // namespace vespalib::portal diff --git a/vespalib/src/vespa/vespalib/portal/http_request.cpp b/vespalib/src/vespa/vespalib/portal/http_request.cpp index 742d88a7334..6cee2e52920 100644 --- a/vespalib/src/vespa/vespalib/portal/http_request.cpp +++ b/vespalib/src/vespa/vespalib/portal/http_request.cpp @@ -15,7 +15,7 @@ void strip_cr(vespalib::string &str) { } } -std::vector<vespalib::string> split(vespalib::stringref str, char sep) { +std::vector<vespalib::string> split(std::string_view str, char sep) { vespalib::string token; std::vector<vespalib::string> list; for (char c: str) { @@ -45,7 +45,7 @@ int decode_hex_digit(char c) { return -1; } -int decode_hex_num(vespalib::stringref src, size_t idx) { +int decode_hex_num(std::string_view src, size_t idx) { if (src.size() < (idx + 2)) { return -1; } @@ -57,7 +57,7 @@ int decode_hex_num(vespalib::stringref src, size_t idx) { return ((a << 4) | b); } -vespalib::string dequote(vespalib::stringref src) { +vespalib::string dequote(std::string_view src) { vespalib::string dst; for (size_t idx = 0; idx < src.size(); ++idx) { char c = src[idx]; diff --git a/vespalib/src/vespa/vespalib/portal/portal.cpp b/vespalib/src/vespa/vespalib/portal/portal.cpp index 32cc9e4c644..0c9a00da3c9 100644 --- a/vespalib/src/vespa/vespalib/portal/portal.cpp +++ b/vespalib/src/vespa/vespalib/portal/portal.cpp @@ -78,8 +78,8 @@ Portal::GetRequest::export_params() const } void -Portal::GetRequest::respond_with_content(vespalib::stringref content_type, - vespalib::stringref content) +Portal::GetRequest::respond_with_content(std::string_view content_type, + std::string_view content) { assert(active()); _conn->respond_with_content(content_type, content); @@ -87,7 +87,7 @@ Portal::GetRequest::respond_with_content(vespalib::stringref content_type, } void -Portal::GetRequest::respond_with_error(int code, vespalib::stringref msg) +Portal::GetRequest::respond_with_error(int code, std::string_view msg) { assert(active()); _conn->respond_with_error(code, msg); diff --git a/vespalib/src/vespa/vespalib/portal/portal.h b/vespalib/src/vespa/vespalib/portal/portal.h index 33379afd28b..9691e2c8798 100644 --- a/vespalib/src/vespa/vespalib/portal/portal.h +++ b/vespalib/src/vespa/vespalib/portal/portal.h @@ -65,9 +65,9 @@ public: bool has_param(const vespalib::string &name) const; const vespalib::string &get_param(const vespalib::string &name) const; std::map<vespalib::string, vespalib::string> export_params() const; - void respond_with_content(vespalib::stringref content_type, - vespalib::stringref content); - void respond_with_error(int code, vespalib::stringref msg); + void respond_with_content(std::string_view content_type, + std::string_view content); + void respond_with_error(int code, std::string_view msg); const net::ConnectionAuthContext &auth_context() const noexcept; ~GetRequest(); }; diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index bccd0fa744e..a0794bcffda 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -63,7 +63,7 @@ asciistream::asciistream() : _precision(6) { } -asciistream::asciistream(stringref buf) : +asciistream::asciistream(std::string_view buf) : _rPos(0), _wbuf(), _rbuf(buf), @@ -84,7 +84,7 @@ asciistream::~asciistream() = default; asciistream::asciistream(const asciistream & rhs) : _rPos(0), - _wbuf(rhs.str()), + _wbuf(rhs.view()), _rbuf(_wbuf.c_str(), _wbuf.size()), _base(rhs._base), _floatSpec(rhs._floatSpec), @@ -629,7 +629,7 @@ asciistream::getline(char delim) } asciistream -asciistream::createFromFile(stringref fileName) +asciistream::createFromFile(std::string_view fileName) { FastOS_File file(vespalib::string(fileName).c_str()); asciistream is; @@ -646,15 +646,15 @@ asciistream::createFromFile(stringref fileName) if (actual != sz) { asciistream e; e << "Failed reading " << sz << " bytes from file " << fileName; - throw IoException(e.str() + " : Error=" + file.getLastErrorString(), IoException::UNSPECIFIED, VESPA_STRLOC); + throw IoException(e.view() + " : Error=" + file.getLastErrorString(), IoException::UNSPECIFIED, VESPA_STRLOC); } - is << stringref(static_cast<const char *>(buf.get()), sz); + is << std::string_view(static_cast<const char *>(buf.get()), sz); } return is; } asciistream -asciistream::createFromDevice(stringref fileName) +asciistream::createFromDevice(std::string_view fileName) { FastOS_File file(vespalib::string(fileName).c_str()); asciistream is; @@ -662,7 +662,7 @@ asciistream::createFromDevice(stringref fileName) constexpr size_t SZ = 64_Ki; auto buf = std::make_unique<char []>(SZ); for (ssize_t actual = file.Read(buf.get(), SZ); actual > 0; actual = file.Read(buf.get(), SZ)) { - is << stringref(buf.get(), actual); + is << std::string_view(buf.get(), actual); } } return is; diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.h b/vespalib/src/vespa/vespalib/stllike/asciistream.h index 010a4348798..b365c1a8127 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.h +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.h @@ -30,7 +30,7 @@ class asciistream { public: asciistream(); - asciistream(stringref buf); + asciistream(std::string_view buf); ~asciistream(); asciistream(const asciistream & rhs); asciistream & operator = (const asciistream & rhs); @@ -43,7 +43,7 @@ public: asciistream & operator << (unsigned char v) { doFill(1); write(&v, 1); return *this; } asciistream & operator << (const char * v) { if (v != nullptr) { size_t n(strlen(v)); doFill(n); write(v, n); } return *this; } asciistream & operator << (const string & v) { doFill(v.size()); write(v.data(), v.size()); return *this; } - asciistream & operator << (stringref v) { doFill(v.size()); write(v.data(), v.size()); return *this; } + asciistream & operator << (std::string_view v) { doFill(v.size()); write(v.data(), v.size()); return *this; } asciistream & operator << (const std::string & v) { doFill(v.size()); write(v.data(), v.size()); return *this; } asciistream & operator << (short v) { return *this << static_cast<long long>(v); } asciistream & operator << (unsigned short v) { return *this << static_cast<unsigned long long>(v); } @@ -60,8 +60,8 @@ public: asciistream & operator >> (Base v) { _base = v; return *this; } asciistream & operator << (FloatSpec v) { _floatSpec = v; return *this; } asciistream & operator >> (FloatSpec v) { _floatSpec = v; return *this; } - asciistream & operator << (FloatModifier v) { _floatModifier = v; return *this; } - asciistream & operator >> (FloatModifier v) { _floatModifier = v; return *this; } + asciistream & operator << (FloatModifier v) { _floatModifier = v; return *this; } + asciistream & operator >> (FloatModifier v) { _floatModifier = v; return *this; } asciistream & operator >> (bool & v); asciistream & operator >> (char & v); asciistream & operator >> (signed char & v); @@ -78,7 +78,8 @@ public: asciistream & operator >> (unsigned long long & v); asciistream & operator >> (float & v); asciistream & operator >> (double & v); - stringref str() const { return stringref(c_str(), size()); } + vespalib::string str() const { return vespalib::string(c_str(), size()); } + std::string_view view() const { return std::string_view(c_str(), size()); } const char * c_str() const { return _rbuf.data() + _rPos; } size_t size() const { return length() - _rPos; } bool empty() const { return size() == 0; } @@ -116,14 +117,14 @@ public: StateSaver(const StateSaver&) = delete; StateSaver& operator=(const StateSaver&) = delete; - explicit StateSaver(asciistream& as) noexcept : - _as(as), - _base(as._base), - _floatSpec(as._floatSpec), - _floatModifier(as._floatModifier), - _width(as._width), - _fill(as._fill), - _precision(as._precision) {} + explicit StateSaver(asciistream& as) noexcept + : _as(as), + _base(as._base), + _floatSpec(as._floatSpec), + _floatModifier(as._floatModifier), + _width(as._width), + _fill(as._fill), + _precision(as._precision) {} ~StateSaver() noexcept { _as._base = _base; _as._floatSpec = _floatSpec; @@ -149,8 +150,8 @@ public: asciistream & operator << (Precision v); asciistream & operator >> (Precision v); void eatWhite(); - static asciistream createFromFile(stringref fileName); - static asciistream createFromDevice(stringref fileName); + static asciistream createFromFile(std::string_view fileName); + static asciistream createFromDevice(std::string_view fileName); string getline(char delim='\n'); char getFill() const noexcept { return _fill; } size_t getWidth() const noexcept { return static_cast<size_t>(_width); } // match input type of setw @@ -170,15 +171,15 @@ private: } void write(const void * buf, size_t len); size_t length() const { return _rbuf.size(); } - size_t _rPos; - string _wbuf; - stringref _rbuf; - Base _base; - FloatSpec _floatSpec; - FloatModifier _floatModifier; - uint32_t _width; - char _fill; - uint8_t _precision; + size_t _rPos; + string _wbuf; + std::string_view _rbuf; + Base _base; + FloatSpec _floatSpec; + FloatModifier _floatModifier; + uint32_t _width; + char _fill; + uint8_t _precision; }; ssize_t getline(asciistream & is, vespalib::string & line, char delim='\n'); diff --git a/vespalib/src/vespa/vespalib/stllike/hash_fun.h b/vespalib/src/vespa/vespalib/stllike/hash_fun.h index 8fecc41b4c1..82bc8564f13 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_fun.h +++ b/vespalib/src/vespa/vespalib/stllike/hash_fun.h @@ -78,13 +78,13 @@ inline size_t hashValue(const void *buf, size_t sz) noexcept { struct hash_strings { size_t operator() (const vespalib::string & arg) const noexcept { return hashValue(arg.data(), arg.size()); } - size_t operator() (vespalib::stringref arg) const noexcept { return hashValue(arg.data(), arg.size()); } + size_t operator() (std::string_view arg) const noexcept { return hashValue(arg.data(), arg.size()); } size_t operator() (const char * arg) const noexcept { return hashValue(arg); } size_t operator() (const std::string& arg) const noexcept { return hashValue(arg.data(), arg.size()); } }; template<> struct hash<const char *> : hash_strings { }; -template<> struct hash<vespalib::stringref> : public hash_strings { }; +template<> struct hash<std::string_view> : public hash_strings { }; template<> struct hash<vespalib::string> : hash_strings {}; template<> struct hash<std::string> : hash_strings {}; diff --git a/vespalib/src/vespa/vespalib/stllike/hash_map.cpp b/vespalib/src/vespa/vespalib/stllike/hash_map.cpp index 482deec3165..329e0e4efd4 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_map.cpp +++ b/vespalib/src/vespa/vespalib/stllike/hash_map.cpp @@ -21,6 +21,7 @@ VESPALIB_HASH_MAP_INSTANTIATE(uint16_t, uint32_t); VESPALIB_HASH_MAP_INSTANTIATE(uint32_t, int32_t); VESPALIB_HASH_MAP_INSTANTIATE(uint32_t, uint32_t); VESPALIB_HASH_MAP_INSTANTIATE(uint32_t, double); +VESPALIB_HASH_MAP_INSTANTIATE(uint64_t, uint16_t); VESPALIB_HASH_MAP_INSTANTIATE(uint64_t, uint32_t); VESPALIB_HASH_MAP_INSTANTIATE(uint64_t, uint64_t); VESPALIB_HASH_MAP_INSTANTIATE(uint64_t, bool); diff --git a/vespalib/src/vespa/vespalib/stllike/hash_set.h b/vespalib/src/vespa/vespalib/stllike/hash_set.h index bbb2868ab2d..94ba1559408 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_set.h +++ b/vespalib/src/vespa/vespalib/stllike/hash_set.h @@ -52,6 +52,9 @@ public: template <typename Func> void for_each(Func func) const { _ht.for_each(func); } + template< typename AltKey> + bool contains(const AltKey key) const { return _ht.find(key) != end(); } + template< typename AltKey > const_iterator find(const AltKey & key) const { return _ht.template find<AltKey>(key); } diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.h b/vespalib/src/vespa/vespalib/stllike/hashtable.h index cf55e38f37e..c56d90a89f8 100644 --- a/vespalib/src/vespa/vespalib/stllike/hashtable.h +++ b/vespalib/src/vespa/vespalib/stllike/hashtable.h @@ -309,18 +309,7 @@ public: } return end(); } - constexpr const_iterator find(const Key & key) const noexcept { - next_t h = hash(key); - if (__builtin_expect(_nodes[h].valid(), true)) { - do { - if (__builtin_expect(_equal(_keyExtractor(_nodes[h].getValue()), key), true)) { - return const_iterator(this, h); - } - h = _nodes[h].getNext(); - } while (h != Node::npos); - } - return end(); - } + const_iterator find(const Key & key) const noexcept; template <typename V> insert_result insert(V && node) { return insert_internal(std::forward<V>(node)); diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.hpp b/vespalib/src/vespa/vespalib/stllike/hashtable.hpp index 290f3e312d1..2ff1a63a56e 100644 --- a/vespalib/src/vespa/vespalib/stllike/hashtable.hpp +++ b/vespalib/src/vespa/vespalib/stllike/hashtable.hpp @@ -99,6 +99,21 @@ hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::find(const AltKey & k } template< typename Key, typename Value, typename Hash, typename Equal, typename KeyExtract, typename Modulator > +typename hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::const_iterator +hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::find(const Key & key) const noexcept { + next_t h = hash(key); + if (__builtin_expect(_nodes[h].valid(), true)) { + do { + if (__builtin_expect(_equal(_keyExtractor(_nodes[h].getValue()), key), true)) { + return const_iterator(this, h); + } + h = _nodes[h].getNext(); + } while (h != Node::npos); + } + return end(); +} + +template< typename Key, typename Value, typename Hash, typename Equal, typename KeyExtract, typename Modulator > void hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::erase(const Key & key) { const_iterator found(find(key)); diff --git a/vespalib/src/vespa/vespalib/stllike/lexical_cast.h b/vespalib/src/vespa/vespalib/stllike/lexical_cast.h index 0e23f87c6fe..63b9714b476 100644 --- a/vespalib/src/vespa/vespalib/stllike/lexical_cast.h +++ b/vespalib/src/vespa/vespalib/stllike/lexical_cast.h @@ -6,7 +6,7 @@ namespace vespalib { template <typename T> -T lexical_cast(const stringref s) +T lexical_cast(const std::string_view s) { T v; asciistream is(s); diff --git a/vespalib/src/vespa/vespalib/stllike/string.cpp b/vespalib/src/vespa/vespalib/stllike/string.cpp index f9009286860..b5080e6cbe0 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.cpp +++ b/vespalib/src/vespa/vespalib/stllike/string.cpp @@ -6,48 +6,6 @@ namespace vespalib { -stringref::size_type -stringref::rfind(const char * s, size_type e) const noexcept { - size_type n = strlen(s); - if (n <= size()) { - size_type sz = std::min(size()-n, e); - const char *b = begin(); - do { - if (s[0] == b[sz]) { - bool found(true); - for(size_t i(1); found && (i < n); i++) { - found = s[i] == b[sz+i]; - } - if (found) { - return sz; - } - } - } while (sz-- > 0); - } - return npos; -} - -stringref::size_type -stringref::find(stringref s, size_type start) const noexcept { - const char *buf = begin()+start; - const char *e = end() - s.size(); - while (buf <= e) { - size_t i(0); - for (; (i < s.size()) && (buf[i] == s[i]); i++); - if (i == s.size()) { - return buf - begin(); - } else { - buf++; - } - } - return npos; -} - -std::ostream & operator << (std::ostream & os, stringref v) -{ - return os.write(v.data(), v.size()); -} - template<uint32_t SS> std::ostream & operator << (std::ostream & os, const small_string<SS> & v) { @@ -66,41 +24,44 @@ std::istream & operator >> (std::istream & is, small_string<SS> & v) template std::ostream & operator << (std::ostream & os, const string & v); template std::istream & operator >> (std::istream & is, string & v); -string -operator + (stringref a, const char * b) noexcept -{ - string t(a); - t += b; - return t; +template class small_string<48>; + +template string operator + (const string & a, const string & b) noexcept; +template string operator + (const string & a, std::string_view b) noexcept; +template string operator + (std::string_view a, const string & b) noexcept; +template string operator + (const string & a, const char * b) noexcept; +template string operator + (const char * a, const string & b) noexcept; + +const string &empty_string() noexcept { + static string empty; + return empty; +} + } -string -operator + (const char * a, stringref b) noexcept +namespace std { + +vespalib::string +operator + (std::string_view a, const char * b) noexcept { - string t(a); + vespalib::string t(a); t += b; return t; } -string -operator + (stringref a, stringref b) noexcept +vespalib::string +operator + (const char * a, std::string_view b) noexcept { - string t(a); + vespalib::string t(a); t += b; return t; } -template class small_string<48>; - -template string operator + (const string & a, const string & b) noexcept; -template string operator + (const string & a, stringref b) noexcept; -template string operator + (stringref a, const string & b) noexcept; -template string operator + (const string & a, const char * b) noexcept; -template string operator + (const char * a, const string & b) noexcept; - -const string &empty_string() noexcept { - static string empty; - return empty; +vespalib::string +operator + (std::string_view a, std::string_view b) noexcept { + vespalib::string t(a); + t += b; + return t; } } diff --git a/vespalib/src/vespa/vespalib/stllike/string.h b/vespalib/src/vespa/vespalib/stllike/string.h index cbbeb94a1b6..2d7ec39aad0 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.h +++ b/vespalib/src/vespa/vespalib/stllike/string.h @@ -11,160 +11,6 @@ namespace vespalib { /** - * This class holds a reference to an external chunk of memory. - * It behaves like a string in many respects. - * It is the responsibility of the programmer to ensure that the - * memory referenced is valid and preferably unchanged for the - * lifetime of the stringref; said lifetime should generally be short. - **/ -class stringref -{ -public: - using const_iterator = const char *; - using size_type = size_t; - static constexpr size_type npos = static_cast<size_type>(-1); - constexpr stringref() noexcept : _s(""), _sz(0) { } - stringref(const char * s) noexcept : _s(s), _sz(strlen(s)) { } - constexpr stringref(const char * s, size_type sz) noexcept : _s(s), _sz(sz) { } - stringref(const std::string & s) noexcept : _s(s.c_str()), _sz(s.size()) { } - stringref(const std::string_view & s) noexcept : _s(s.data()), _sz(s.size()) { } - stringref(const stringref &) noexcept = default; - stringref & operator =(const stringref &) noexcept = default; - stringref(stringref &&) noexcept = default; - stringref & operator =(stringref &&) noexcept = default; - - /** - * return a pointer to the data held, or nullptr. - * Note that the data may not be zero terminated, and a default - * constructed stringref will give a nullptr pointer back. If you - * need to make sure data() gives a valid zero-terminated string - * you should make a string from the stringref. - **/ - [[nodiscard]] const char * data() const noexcept { return _s; } - [[nodiscard]] size_type size() const noexcept { return _sz; } - [[nodiscard]] size_type length() const noexcept { return size(); } - [[nodiscard]] bool empty() const noexcept { return _sz == 0; } - [[nodiscard]] const char * begin() const noexcept { return data(); } - [[nodiscard]] const char * end() const noexcept { return begin() + size(); } - [[nodiscard]] const char * rbegin() const noexcept { return end() - 1; } - [[nodiscard]] const char * rend() const noexcept { return begin() - 1; } - [[nodiscard]] stringref substr(size_type start, size_type sz=npos) const noexcept { - if (start < size()) { - return {data() + start, std::min(sz, size()-start)}; - } - return {}; - } - - /** - * Find the first occurrence of a string, searching from @c start - * - * @param s characters to search for. Must be zero terminated to make sense. - * @param start index at which the search will be started - * @return index from the start of the string at which the character - * was found, or npos if the character could not be located - */ - size_type find(const char * s, size_type start=0) const noexcept { - const char *buf = begin()+start; - const char *found = (const char *)strstr(buf, s); - return (found != nullptr) ? (found - begin()) : (size_type)npos; - } - /** - * Find the first occurrence of a string, searching from @c start - * - * @param s characters to search for. Must be zero terminated to make sense. - * @param start index at which the search will be started - * @return index from the start of the string at which the character - * was found, or npos if the character could not be located - */ - [[nodiscard]] size_type find(stringref s, size_type start=0) const noexcept; - /** - * Find the first occurrence of a character, searching from @c start - * - * @param c character to search for - * @param start index at which the search will be started - * @return index from the start of the string at which the character - * was found, or npos if the character could not be located - */ - [[nodiscard]] size_type find(char c, size_type start=0) const noexcept { - const char *buf = begin()+start; - const char *found = (const char *)memchr(buf, c, _sz-start); - return (found != nullptr) ? (found - begin()) : (size_type)npos; - } - /** - * Find the last occurrence of a substring, starting at e and - * searching in reverse order. - * - * @param s substring to search for - * @param e index from which the search will be started - * @return index from the start of the string at which the substring - * was found, or npos if the substring could not be located - */ - [[nodiscard]] size_type rfind(char c, size_type e=npos) const noexcept { - if (!empty()) { - const char *b = begin(); - for (size_type i(std::min(size()-1, e) + 1); i > 0;) { - --i; - if (c == b[i]) { - return i; - } - } - } - return npos; - } - - /** - * Find the last occurrence of a substring, starting at e and - * searching in reverse order. - * - * @param s substring to search for - * @param e index from which the search will be started - * @return index from the start of the string at which the substring - * was found, or npos if the substring could not be located - */ - size_type rfind(const char * s, size_type e=npos) const noexcept; - [[nodiscard]] int compare(stringref s) const noexcept { return compare(s.data(), s.size()); } - - /** - * Returns true iff input string is a prefix of this string. - */ - [[nodiscard]] bool starts_with(stringref prefix) const noexcept { - if (prefix.size() > size()) { - return false; - } - return (memcmp(data(), prefix.data(), prefix.size()) == 0); - } - - const char & operator [] (size_t i) const noexcept { return _s[i]; } - operator std::string () const { return {_s, _sz}; } - operator std::string_view () const { return {_s, _sz}; } - std::strong_ordering operator <=>(const char * s) const noexcept { return strong_compare(s, strlen(s)); } - std::strong_ordering operator <=>(const std::string & s) const noexcept { return strong_compare(s.data(), s.size()); } - std::strong_ordering operator <=>(std::string_view s) const noexcept { return strong_compare(s.data(), s.size()); } - std::strong_ordering operator <=>(stringref s) const noexcept { return strong_compare(s.data(), s.size()); } - bool operator ==(const char * s) const noexcept { return strong_compare(s, strlen(s)) == std::strong_ordering::equal; } - bool operator ==(const std::string & s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } - bool operator ==(std::string_view s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } - bool operator ==(stringref s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } - friend std::ostream & operator << (std::ostream & os, stringref v); -private: - std::strong_ordering strong_compare(const char *s, size_type sz) const noexcept { - int res = compare(s, sz); - return (res < 0) - ? std::strong_ordering::less - : (res > 0) - ? std::strong_ordering::greater - : std::strong_ordering::equal; - } - int compare(const char *s, size_type sz) const noexcept { - int diff(memcmp(_s, s, std::min(sz, size()))); - return (diff != 0) ? diff : (size() - sz); - } - const char *_s; - size_type _sz; -}; - - -/** * class intended as a mostly-drop-in replacement for std::string * optimized for good multi-core performance using the well-known * "small-string optimization" where a small chunk of memory is @@ -189,9 +35,8 @@ public: constexpr small_string() noexcept : _buf(_stack), _sz(0), _bufferSize(StackSize) { _stack[0] = '\0'; } small_string(const char * s) noexcept : _buf(_stack), _sz(s ? strlen(s) : 0) { init(s); } small_string(const void * s, size_type sz) noexcept : _buf(_stack), _sz(sz) { init(s); } - small_string(stringref s) noexcept : _buf(_stack), _sz(s.size()) { init(s.data()); } small_string(const std::string & s) noexcept : _buf(_stack), _sz(s.size()) { init(s.data()); } - small_string(std::string_view s) noexcept : _buf(_stack), _sz(s.size()) { init(s.data()); } + explicit small_string(std::string_view s) noexcept : _buf(_stack), _sz(s.size()) { init(s.data()); } small_string(small_string && rhs) noexcept : _sz(rhs.size()), _bufferSize(rhs._bufferSize) { @@ -231,24 +76,21 @@ public: small_string& operator= (const small_string &rhs) noexcept { return assign(rhs.data(), rhs.size()); } - small_string & operator= (stringref rhs) noexcept { - return assign(rhs.data(), rhs.size()); - } + small_string& operator= (const char *s) noexcept { return assign(s); } small_string& operator= (const std::string &rhs) noexcept { - return operator= (stringref(rhs)); + return assign(rhs.data(), rhs.size()); } small_string& operator= (std::string_view rhs) noexcept { - return operator= (stringref(rhs)); + return assign(rhs.data(), rhs.size()); } void swap(small_string & rhs) noexcept { std::swap(*this, rhs); } - operator std::string () const { return {c_str(), size()}; } - operator std::string_view () const { return {c_str(), size()}; } - operator stringref () const noexcept { return stringref(c_str(), size()); } + operator std::string () const noexcept { return {c_str(), size()}; } + operator std::string_view () const noexcept { return {c_str(), size()}; } [[nodiscard]] char at(size_t i) const noexcept { return buffer()[i]; } char & at(size_t i) noexcept { return buffer()[i]; } const char & operator [] (size_t i) const noexcept { return buffer()[i]; } @@ -273,7 +115,7 @@ public: /** * Returns true iff input string is a prefix of this string. */ - [[nodiscard]] bool starts_with(stringref prefix) const noexcept { + [[nodiscard]] bool starts_with(std::string_view prefix) const noexcept { if (prefix.size() > size()) { return false; } @@ -365,24 +207,24 @@ public: } small_string & assign(const char * s) noexcept { return assign(s, strlen(s)); } small_string & assign(const void * s, size_type sz) noexcept; - small_string & assign(stringref s, size_type pos, size_type sz) noexcept { + small_string & assign(std::string_view s, size_type pos, size_type sz) noexcept { return assign(s.data() + pos, sz); } - small_string & assign(stringref rhs) noexcept { + small_string & assign(std::string_view rhs) noexcept { if (data() != rhs.data()) assign(rhs.data(), rhs.size()); return *this; } small_string & push_back(char c) noexcept { return append(&c, 1); } small_string & append(char c) noexcept { return append(&c, 1); } small_string & append(const char * s) noexcept { return append(s, strlen(s)); } - small_string & append(stringref s) noexcept { return append(s.data(), s.size()); } + small_string & append(std::string_view s) noexcept { return append(s.data(), s.size()); } small_string & append(const std::string & s) noexcept { return append(s.data(), s.size()); } small_string & append(const small_string & s) noexcept { return append(s.data(), s.size()); } small_string & append(const void * s, size_type sz) noexcept; small_string & operator += (char c) noexcept { return append(c); } small_string & operator += (const char * s) noexcept { return append(s); } - small_string & operator += (stringref s) noexcept { return append(s); } small_string & operator += (const std::string & s) noexcept { return append(s); } + small_string & operator += (std::string_view s) noexcept { return append(s); } small_string & operator += (const small_string & s) noexcept { return append(s); } /** @@ -403,7 +245,7 @@ public: } small_string & insert(iterator p, const_iterator f, const_iterator l) noexcept { return insert(p-c_str(), f, l-f); } - small_string & insert(size_type start, stringref v) noexcept { return insert(start, v.data(), v.size()); } + small_string & insert(size_type start, std::string_view v) noexcept { return insert(start, v.data(), v.size()); } small_string & insert(size_type start, const void * v, size_type sz) noexcept; /** @@ -494,15 +336,15 @@ public: std::strong_ordering operator <=>(const char * s) const noexcept { return strong_compare(s, strlen(s)); } std::strong_ordering operator <=>(const std::string & s) const noexcept { return strong_compare(s.data(), s.size()); } std::strong_ordering operator <=>(const small_string & s) const noexcept { return strong_compare(s.data(), s.size()); } - std::strong_ordering operator <=>(stringref s) const noexcept { return strong_compare(s.data(), s.size()); } + std::strong_ordering operator <=>(std::string_view s) const noexcept { return strong_compare(s.data(), s.size()); } bool operator ==(const char * s) const noexcept { return strong_compare(s, strlen(s)) == std::strong_ordering::equal; } bool operator ==(const std::string & s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } bool operator ==(const small_string & s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } - bool operator ==(stringref s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } + bool operator ==(std::string_view s) const noexcept { return strong_compare(s.data(), s.size()) == std::strong_ordering::equal; } template<typename T> bool operator != (const T& s) const noexcept { return ! operator == (s); } - [[nodiscard]] int compare(const small_string & s) const noexcept { return compare(s.c_str(), s.size()); } + [[nodiscard]] int compare(std::string_view s) const noexcept { return compare(s.data(), s.size()); } int compare(const char *s, size_t sz) const noexcept { int diff(memcmp(buffer(), s, std::min(sz, size()))); return (diff != 0) ? diff : (size() - sz); @@ -637,11 +479,11 @@ operator + (const small_string<StackSize> & a, const small_string<StackSize> & b template<uint32_t StackSize> small_string<StackSize> -operator + (const small_string<StackSize> & a, stringref b) noexcept; +operator + (const small_string<StackSize> & a, std::string_view b) noexcept; template<uint32_t StackSize> small_string<StackSize> -operator + (stringref a, const small_string<StackSize> & b) noexcept; +operator + (std::string_view a, const small_string<StackSize> & b) noexcept; template<uint32_t StackSize> small_string<StackSize> @@ -651,22 +493,18 @@ template<uint32_t StackSize> small_string<StackSize> operator + (const char * a, const small_string<StackSize> & b) noexcept; -string operator + (stringref a, stringref b) noexcept; -string operator + (const char * a, stringref b) noexcept; -string operator + (stringref a, const char * b) noexcept; - -inline bool contains(stringref text, stringref key) noexcept { - return text.find(key) != stringref::npos; +inline bool contains(std::string_view text, std::string_view key) noexcept { + return text.find(key) != std::string_view::npos; } -inline bool starts_with(stringref text, stringref key) noexcept { +inline bool starts_with(std::string_view text, std::string_view key) noexcept { if (text.size() >= key.size()) { return memcmp(text.begin(), key.begin(), key.size()) == 0; } return false; } -inline bool ends_with(stringref text, stringref key) noexcept { +inline bool ends_with(std::string_view text, std::string_view key) noexcept { if (text.size() >= key.size()) { return memcmp(text.end()-key.size(), key.begin(), key.size()) == 0; } @@ -680,7 +518,7 @@ const string &empty_string() noexcept; * Utility function to format an unsigned integer into a new * string instance. **/ -static inline string stringify(uint64_t number) +static inline string stringify(uint64_t number) noexcept { char digits[64]; int numdigits = 0; @@ -697,3 +535,10 @@ static inline string stringify(uint64_t number) } // namespace vespalib +namespace std { + +vespalib::string operator+(std::string_view a, std::string_view b) noexcept; +vespalib::string operator+(const char *a, std::string_view b) noexcept; +vespalib::string operator+(std::string_view a, const char *b) noexcept; + +} diff --git a/vespalib/src/vespa/vespalib/stllike/string.hpp b/vespalib/src/vespa/vespalib/stllike/string.hpp index e0243d842e8..9fd99dd9b68 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.hpp +++ b/vespalib/src/vespa/vespalib/stllike/string.hpp @@ -171,7 +171,7 @@ operator + (const small_string<StackSize> & a, const small_string<StackSize> & b template<uint32_t StackSize> small_string<StackSize> -operator + (const small_string<StackSize> & a, stringref b) noexcept +operator + (const small_string<StackSize> & a, std::string_view b) noexcept { small_string<StackSize> t(a); t += b; @@ -180,7 +180,7 @@ operator + (const small_string<StackSize> & a, stringref b) noexcept template<uint32_t StackSize> small_string<StackSize> -operator + (stringref a, const small_string<StackSize> & b) noexcept +operator + (std::string_view a, const small_string<StackSize> & b) noexcept { small_string<StackSize> t(a); t += b; diff --git a/vespalib/src/vespa/vespalib/test/peer_policy_utils.cpp b/vespalib/src/vespa/vespalib/test/peer_policy_utils.cpp index ecb9f6a3cd9..217d2eaa96a 100644 --- a/vespalib/src/vespa/vespalib/test/peer_policy_utils.cpp +++ b/vespalib/src/vespa/vespalib/test/peer_policy_utils.cpp @@ -4,15 +4,15 @@ namespace vespalib::net::tls { -RequiredPeerCredential required_cn(vespalib::stringref pattern) { +RequiredPeerCredential required_cn(std::string_view pattern) { return {RequiredPeerCredential::Field::CN, pattern}; } -RequiredPeerCredential required_san_dns(vespalib::stringref pattern) { +RequiredPeerCredential required_san_dns(std::string_view pattern) { return {RequiredPeerCredential::Field::SAN_DNS, pattern}; } -RequiredPeerCredential required_san_uri(vespalib::stringref pattern) { +RequiredPeerCredential required_san_uri(std::string_view pattern) { return {RequiredPeerCredential::Field::SAN_URI, pattern}; } diff --git a/vespalib/src/vespa/vespalib/test/peer_policy_utils.h b/vespalib/src/vespa/vespalib/test/peer_policy_utils.h index d186705f172..7398136482d 100644 --- a/vespalib/src/vespa/vespalib/test/peer_policy_utils.h +++ b/vespalib/src/vespa/vespalib/test/peer_policy_utils.h @@ -6,9 +6,9 @@ namespace vespalib::net::tls { -RequiredPeerCredential required_cn(vespalib::stringref pattern); -RequiredPeerCredential required_san_dns(vespalib::stringref pattern); -RequiredPeerCredential required_san_uri(vespalib::stringref pattern); +RequiredPeerCredential required_cn(std::string_view pattern); +RequiredPeerCredential required_san_dns(std::string_view pattern); +RequiredPeerCredential required_san_uri(std::string_view pattern); PeerPolicy policy_with(std::vector<RequiredPeerCredential> creds); PeerPolicy policy_with(std::vector<RequiredPeerCredential> creds, CapabilitySet capabilities); AuthorizedPeers authorized_peers(std::vector<PeerPolicy> peer_policies); diff --git a/vespalib/src/vespa/vespalib/text/lowercase.cpp b/vespalib/src/vespa/vespalib/text/lowercase.cpp index 3a6fe194e2c..c288cc09402 100644 --- a/vespalib/src/vespa/vespalib/text/lowercase.cpp +++ b/vespalib/src/vespa/vespalib/text/lowercase.cpp @@ -6,7 +6,7 @@ namespace vespalib { vespalib::string -LowerCase::convert(vespalib::stringref input) +LowerCase::convert(std::string_view input) { vespalib::string output; Utf8Reader r(input); @@ -21,7 +21,7 @@ LowerCase::convert(vespalib::stringref input) } std::vector<uint32_t> -LowerCase::convert_to_ucs4(vespalib::stringref input) +LowerCase::convert_to_ucs4(std::string_view input) { std::vector<uint32_t> result; result.reserve(input.size()); diff --git a/vespalib/src/vespa/vespalib/text/lowercase.h b/vespalib/src/vespa/vespalib/text/lowercase.h index c0c196fa6a2..1a8328c6e85 100644 --- a/vespalib/src/vespa/vespalib/text/lowercase.h +++ b/vespalib/src/vespa/vespalib/text/lowercase.h @@ -53,25 +53,19 @@ public: int lowblock = codepoint >> 8; unsigned char lb = codepoint & 0xFF; - /**/ if (lowblock == 16) { + if (lowblock == 16) { return lowercase_16_block[lb]; - } - else if (lowblock == 30) { + } else if (lowblock == 30) { return lowercase_30_block[lb]; - } - else if (lowblock == 31) { + } else if (lowblock == 31) { return lowercase_31_block[lb]; - } - else if (lowblock == 33) { + } else if (lowblock == 33) { return lowercase_33_block[lb]; - } - else if (lowblock == 44) { + } else if (lowblock == 44) { return lowercase_44_block[lb]; - } - else if (lowblock == 260) { + } else if (lowblock == 260) { return lowercase_260_block[lb]; - } - else { + } else { return codepoint; } } @@ -103,15 +97,12 @@ public: * any bytes that aren't valid UTF-8 with the Unicode REPLACEMENT * CHARACTER (U+FFFD). **/ - static vespalib::string convert(vespalib::stringref input); + static vespalib::string convert(std::string_view input); /** * Lowercase a string in UTF-8 format while converting it to UCS-4 codepoints. */ - static std::vector<uint32_t> convert_to_ucs4(vespalib::stringref input); - static std::vector<uint32_t> convert_to_ucs4(std::string_view input) { - return convert_to_ucs4(vespalib::stringref(input.data(), input.size())); - } + static std::vector<uint32_t> convert_to_ucs4(std::string_view input); }; diff --git a/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp b/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp index 7c2421cf464..81d1278e6ee 100644 --- a/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp +++ b/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp @@ -7,7 +7,7 @@ namespace { class AsciiSet { public: - explicit AsciiSet(vespalib::stringref s) { + explicit AsciiSet(std::string_view s) { memset(_set, 0, sizeof(_set)); for (char c : s) { add(c); @@ -32,7 +32,7 @@ using TokenList = vespalib::StringTokenizer::TokenList; * of characters contained in the strip set. **/ Token -stripString(vespalib::stringref source, const AsciiSet & strip) +stripString(std::string_view source, const AsciiSet & strip) { Token::size_type start = 0; while (start < source.size() && strip.contains(source[start])) { @@ -46,7 +46,7 @@ stripString(vespalib::stringref source, const AsciiSet & strip) } size_t -countSeparators(vespalib::stringref source, const AsciiSet & sep) { +countSeparators(std::string_view source, const AsciiSet & sep) { size_t count(0); for (char c : source) { if (sep.contains(c)) { @@ -57,7 +57,7 @@ countSeparators(vespalib::stringref source, const AsciiSet & sep) { } void -parse(TokenList& output, vespalib::stringref source, const AsciiSet & separators, const AsciiSet & strip) +parse(TokenList& output, std::string_view source, const AsciiSet & separators, const AsciiSet & strip) { Token::size_type start = 0; for (Token::size_type i = 0; i < source.size(); ++i) { @@ -75,9 +75,9 @@ parse(TokenList& output, vespalib::stringref source, const AsciiSet & separators namespace vespalib { -StringTokenizer::StringTokenizer(vespalib::stringref source, - vespalib::stringref separators, - vespalib::stringref strip) +StringTokenizer::StringTokenizer(std::string_view source, + std::string_view separators, + std::string_view strip) : _tokens() { AsciiSet sep(separators); diff --git a/vespalib/src/vespa/vespalib/text/stringtokenizer.h b/vespalib/src/vespa/vespalib/text/stringtokenizer.h index d59ad7e63b6..838ec698f90 100644 --- a/vespalib/src/vespa/vespalib/text/stringtokenizer.h +++ b/vespalib/src/vespa/vespalib/text/stringtokenizer.h @@ -21,7 +21,7 @@ namespace vespalib { class StringTokenizer { public: - using Token = vespalib::stringref; + using Token = std::string_view; using TokenList = std::vector<Token>; using Iterator = TokenList::const_iterator; @@ -41,15 +41,15 @@ public: * @param separators The characters to be used as token separators * @param strip Characters to be stripped from both ends of each token **/ - explicit StringTokenizer(vespalib::stringref source) + explicit StringTokenizer(std::string_view source) : StringTokenizer(source, ",") {} - StringTokenizer(vespalib::stringref source, vespalib::stringref separators) + StringTokenizer(std::string_view source, std::string_view separators) : StringTokenizer(source, separators, " \t\f\r\n") {} - StringTokenizer(vespalib::stringref source, - vespalib::stringref separators, - vespalib::stringref strip); + StringTokenizer(std::string_view source, + std::string_view separators, + std::string_view strip); StringTokenizer(StringTokenizer &&) noexcept = default; StringTokenizer & operator=(StringTokenizer &&) noexcept = default; ~StringTokenizer(); diff --git a/vespalib/src/vespa/vespalib/text/utf8.h b/vespalib/src/vespa/vespalib/text/utf8.h index 26439f16d66..9293fdf737c 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.h +++ b/vespalib/src/vespa/vespalib/text/utf8.h @@ -170,7 +170,7 @@ protected: * @brief Reader class that wraps a block of data to get UTF-8 characters from **/ class Utf8Reader - : public Utf8, private stringref + : public Utf8, private std::string_view { private: size_type _pos; @@ -182,8 +182,8 @@ public: * Construct a reader for the given block of data * @param input data to read UTF-8 from (can be read-only) **/ - Utf8Reader(stringref input) noexcept - : stringref(input), _pos(0) + Utf8Reader(std::string_view input) noexcept + : std::string_view(input), _pos(0) {} /** @@ -192,7 +192,7 @@ public: * @param sz size of the block in bytes **/ Utf8Reader(const char *start, size_t sz) noexcept - : stringref(start, sz), _pos(0) + : std::string_view(start, sz), _pos(0) {} /** diff --git a/vespalib/src/vespa/vespalib/util/arrayref.h b/vespalib/src/vespa/vespalib/util/arrayref.h index 84e7046f217..319a8170334 100644 --- a/vespalib/src/vespa/vespalib/util/arrayref.h +++ b/vespalib/src/vespa/vespalib/util/arrayref.h @@ -9,7 +9,7 @@ namespace vespalib { /** * This is a simple wrapper class for a typed array with no memory ownership. - * It is similar to vespalib::stringref + * It is similar to std::string_view **/ template <typename T> class ArrayRef { diff --git a/vespalib/src/vespa/vespalib/util/exception.cpp b/vespalib/src/vespa/vespalib/util/exception.cpp index 126dc7b593f..54e87f747c0 100644 --- a/vespalib/src/vespa/vespalib/util/exception.cpp +++ b/vespalib/src/vespa/vespalib/util/exception.cpp @@ -58,7 +58,7 @@ swap(ExceptionPtr &a, ExceptionPtr &b) //----------------------------------------------------------------------------- -Exception::Exception(stringref msg, stringref location, int skipStack) +Exception::Exception(std::string_view msg, std::string_view location, int skipStack) : _what(), _msg(msg), _location(location), @@ -68,7 +68,7 @@ Exception::Exception(stringref msg, stringref location, int skipStack) { } -Exception::Exception(stringref msg, const Exception &cause, stringref location, int skipStack) +Exception::Exception(std::string_view msg, const Exception &cause, std::string_view location, int skipStack) : _what(), _msg(msg), _location(location), diff --git a/vespalib/src/vespa/vespalib/util/exception.h b/vespalib/src/vespa/vespalib/util/exception.h index 54409e045b7..de54b4a4678 100644 --- a/vespalib/src/vespa/vespalib/util/exception.h +++ b/vespalib/src/vespa/vespalib/util/exception.h @@ -61,10 +61,10 @@ #define VESPA_DEFINE_EXCEPTION(MyClass, Parent) \ class MyClass : public Parent { \ public: \ - explicit MyClass(vespalib::stringref msg, \ - vespalib::stringref location = "", int skipStack = 0); \ - MyClass(vespalib::stringref msg, const Exception &cause, \ - vespalib::stringref location = "", int skipStack = 0); \ + explicit MyClass(std::string_view msg, \ + std::string_view location = "", int skipStack = 0); \ + MyClass(std::string_view msg, const Exception &cause, \ + std::string_view location = "", int skipStack = 0); \ MyClass(const MyClass &); \ MyClass & operator=(const MyClass &) = delete; \ MyClass(MyClass &&) noexcept; \ @@ -82,11 +82,11 @@ public: \ * @param MyClass the name of your class **/ #define VESPA_IMPLEMENT_EXCEPTION(MyClass, Parent) \ - MyClass::MyClass(vespalib::stringref msg, \ - vespalib::stringref location, int skipStack) \ + MyClass::MyClass(std::string_view msg, \ + std::string_view location, int skipStack) \ : Parent(msg, location, skipStack + 1) {} \ - MyClass::MyClass(vespalib::stringref msg, const Exception &cause, \ - vespalib::stringref location, int skipStack) \ + MyClass::MyClass(std::string_view msg, const Exception &cause, \ + std::string_view location, int skipStack) \ : Parent(msg, cause, location, skipStack + 1) {} \ MyClass::MyClass(const MyClass &) = default; \ MyClass::MyClass(MyClass &&) noexcept = default; \ @@ -195,7 +195,7 @@ public: * should send (skipStack + 1) to the parent constructor (see * \ref VESPA_DEFINE_EXCEPTION for subclass implementation). **/ - explicit Exception(stringref msg, stringref location = "", int skipStack = 0); + explicit Exception(std::string_view msg, std::string_view location = "", int skipStack = 0); /** * @brief Construct an exception with a message, a causing exception, and a source code location. * @param msg A user-readable message describing the problem @@ -207,8 +207,8 @@ public: * should send (skipStack + 1) to the parent constructor (see * \ref VESPA_DEFINE_EXCEPTION for subclass implementation). **/ - Exception(stringref msg, const Exception &cause, - stringref location = "", int skipStack = 0); + Exception(std::string_view msg, const Exception &cause, + std::string_view location = "", int skipStack = 0); Exception(const Exception &); Exception & operator = (const Exception &); Exception(Exception &&) noexcept; diff --git a/vespalib/src/vespa/vespalib/util/exceptions.cpp b/vespalib/src/vespa/vespalib/util/exceptions.cpp index 5caea47f2cb..f1277d71dfe 100644 --- a/vespalib/src/vespa/vespalib/util/exceptions.cpp +++ b/vespalib/src/vespa/vespalib/util/exceptions.cpp @@ -41,12 +41,12 @@ ExceptionWithPayload::what() const noexcept { return _msg.c_str(); } -ExceptionWithPayload::ExceptionWithPayload(vespalib::stringref msg) +ExceptionWithPayload::ExceptionWithPayload(std::string_view msg) : std::exception(), _msg(msg), _payload() { } -ExceptionWithPayload::ExceptionWithPayload(vespalib::stringref msg, Anything::UP payload) +ExceptionWithPayload::ExceptionWithPayload(std::string_view msg, Anything::UP payload) : std::exception(), _msg(msg), _payload(std::move(payload)) @@ -70,27 +70,27 @@ SilenceUncaughtException::~SilenceUncaughtException() } vespalib::string -PortListenException::make_message(int port, vespalib::stringref protocol, - vespalib::stringref msg) +PortListenException::make_message(int port, std::string_view protocol, + std::string_view msg) { return make_string("failed to listen on port %d with protocol %s%s%s", port, vespalib::string(protocol).c_str(), msg.empty() ? "" : ": ", vespalib::string(msg).c_str()); } -PortListenException::PortListenException(int port, vespalib::stringref protocol, - vespalib::stringref msg, - vespalib::stringref location, int skipStack) +PortListenException::PortListenException(int port, std::string_view protocol, + std::string_view msg, + std::string_view location, int skipStack) : Exception(make_message(port, protocol, msg), location, skipStack + 1), _port(port), _protocol(protocol) { } -PortListenException::PortListenException(int port, vespalib::stringref protocol, +PortListenException::PortListenException(int port, std::string_view protocol, const Exception &cause, - vespalib::stringref msg, - vespalib::stringref location, int skipStack) + std::string_view msg, + std::string_view location, int skipStack) : Exception(make_message(port, protocol, msg), cause, location, skipStack + 1), _port(port), _protocol(protocol) @@ -106,15 +106,15 @@ PortListenException::~PortListenException() = default; //----------------------------------------------------------------------------- -IoException::IoException(stringref msg, Type type, - stringref location, int skipStack) +IoException::IoException(std::string_view msg, Type type, + std::string_view location, int skipStack) : Exception(createMessage(msg, type), location, skipStack+1), _type(type) { } -IoException::IoException(stringref msg, Type type, - const Exception& cause, stringref location, +IoException::IoException(std::string_view msg, Type type, + const Exception& cause, std::string_view location, int skipStack) : Exception(createMessage(msg, type), cause, location, skipStack+1), _type(type) @@ -127,7 +127,7 @@ IoException & IoException::operator =(IoException &&) noexcept = default; IoException::~IoException() = default; string -IoException::createMessage(stringref msg, Type type) +IoException::createMessage(std::string_view msg, Type type) { vespalib::asciistream ost; switch (type) { diff --git a/vespalib/src/vespa/vespalib/util/exceptions.h b/vespalib/src/vespa/vespalib/util/exceptions.h index 3085179ec5c..a0fa29a1548 100644 --- a/vespalib/src/vespa/vespalib/util/exceptions.h +++ b/vespalib/src/vespa/vespalib/util/exceptions.h @@ -70,8 +70,8 @@ public: using UP = std::unique_ptr<Anything>; virtual ~Anything() = default; }; - explicit ExceptionWithPayload(vespalib::stringref msg); - ExceptionWithPayload(vespalib::stringref msg, Anything::UP payload); + explicit ExceptionWithPayload(std::string_view msg); + ExceptionWithPayload(std::string_view msg, Anything::UP payload); ExceptionWithPayload(ExceptionWithPayload &&) noexcept; ExceptionWithPayload & operator = (ExceptionWithPayload &&) noexcept; ~ExceptionWithPayload() override; @@ -84,8 +84,8 @@ private: class OOMException : public ExceptionWithPayload { public: - explicit OOMException(vespalib::stringref msg) : ExceptionWithPayload(msg) { } - OOMException(vespalib::stringref msg, Anything::UP payload) : ExceptionWithPayload(msg, std::move(payload)) { } + explicit OOMException(std::string_view msg) : ExceptionWithPayload(msg) { } + OOMException(std::string_view msg, Anything::UP payload) : ExceptionWithPayload(msg, std::move(payload)) { } }; /** @@ -98,13 +98,13 @@ private: int _port; vespalib::string _protocol; - vespalib::string make_message(int port, vespalib::stringref protocol, vespalib::stringref msg); + vespalib::string make_message(int port, std::string_view protocol, std::string_view msg); public: - PortListenException(int port, vespalib::stringref protocol, vespalib::stringref msg = "", - vespalib::stringref location = "", int skipStack = 0); - PortListenException(int port, vespalib::stringref protocol, const Exception &cause, vespalib::stringref msg = "", - vespalib::stringref location = "", int skipStack = 0); + PortListenException(int port, std::string_view protocol, std::string_view msg = "", + std::string_view location = "", int skipStack = 0); + PortListenException(int port, std::string_view protocol, const Exception &cause, std::string_view msg = "", + std::string_view location = "", int skipStack = 0); PortListenException(PortListenException &&) noexcept; PortListenException & operator = (PortListenException &&) noexcept; PortListenException(const PortListenException &); @@ -128,8 +128,8 @@ public: TOO_MANY_OPEN_FILES, DIRECTORY_HAVE_CONTENT, FILE_FULL, ALREADY_EXISTS }; - IoException(stringref msg, Type type, stringref location, int skipStack = 0); - IoException(stringref msg, Type type, const Exception& cause, stringref location, int skipStack = 0); + IoException(std::string_view msg, Type type, std::string_view location, int skipStack = 0); + IoException(std::string_view msg, Type type, const Exception& cause, std::string_view location, int skipStack = 0); IoException(const IoException &); IoException & operator =(const IoException &) = delete; IoException(IoException &&) noexcept; @@ -138,7 +138,7 @@ public: VESPA_DEFINE_EXCEPTION_SPINE(IoException); - static string createMessage(stringref msg, Type type); + static string createMessage(std::string_view msg, Type type); Type getType() const { return _type; } diff --git a/vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp b/vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp index 1caa87c960a..1bf69f0cf45 100644 --- a/vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp +++ b/vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp @@ -69,14 +69,14 @@ GrowableByteBuffer::putDouble(double v) } void -GrowableByteBuffer::putString(vespalib::stringref v) +GrowableByteBuffer::putString(std::string_view v) { putInt(v.size()); putBytes(v.data(), v.size()); } void -GrowableByteBuffer::put_c_string(vespalib::stringref v) +GrowableByteBuffer::put_c_string(std::string_view v) { putInt(v.size() + 1); putBytes(v.data(), v.size()); diff --git a/vespalib/src/vespa/vespalib/util/growablebytebuffer.h b/vespalib/src/vespa/vespalib/util/growablebytebuffer.h index 38d3991da60..e3ce2babf9e 100644 --- a/vespalib/src/vespa/vespalib/util/growablebytebuffer.h +++ b/vespalib/src/vespa/vespalib/util/growablebytebuffer.h @@ -70,13 +70,13 @@ public: /** Adds a string to the buffer (without nul-termination). */ - void putString(vespalib::stringref v); + void putString(std::string_view v); /** * Adds a string to the buffer (including nul-termination). * This matches com.yahoo.vespa.objects.Deserializer.getString. */ - void put_c_string(vespalib::stringref v); + void put_c_string(std::string_view v); /** Adds a single byte to the buffer. diff --git a/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.cpp b/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.cpp index 8ea05a3252b..4d44e849789 100644 --- a/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.cpp +++ b/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.cpp @@ -20,8 +20,8 @@ ISequencedTaskExecutor::executeTasks(TaskList tasks) { } ISequencedTaskExecutor::ExecutorId -ISequencedTaskExecutor::getExecutorIdFromName(stringref componentId) const { - hash<stringref> hashfun; +ISequencedTaskExecutor::getExecutorIdFromName(std::string_view componentId) const { + hash<std::string_view> hashfun; return getExecutorId(hashfun(componentId)); } diff --git a/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.h b/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.h index 8ee26ebdc2e..2f69ca1be48 100644 --- a/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.h +++ b/vespalib/src/vespa/vespalib/util/isequencedtaskexecutor.h @@ -41,7 +41,7 @@ public: virtual ExecutorId getExecutorId(uint64_t componentId) const = 0; uint32_t getNumExecutors() const { return _numExecutors; } - ExecutorId getExecutorIdFromName(stringref componentId) const; + ExecutorId getExecutorIdFromName(std::string_view componentId) const; /** * Returns an executor id that is NOT equal to the given executor id, diff --git a/vespalib/src/vespa/vespalib/util/jsonexception.cpp b/vespalib/src/vespa/vespalib/util/jsonexception.cpp index 064c1b98672..fffc1d02479 100644 --- a/vespalib/src/vespa/vespalib/util/jsonexception.cpp +++ b/vespalib/src/vespa/vespalib/util/jsonexception.cpp @@ -6,8 +6,8 @@ namespace vespalib { VESPA_IMPLEMENT_EXCEPTION_SPINE(JsonStreamException); -JsonStreamException::JsonStreamException(stringref reason, stringref history, - stringref location, int skipStack) +JsonStreamException::JsonStreamException(std::string_view reason, std::string_view history, + std::string_view location, int skipStack) : Exception(reason + (history.empty() ? "" : "\nHistory:\n" + history), location, skipStack + 1), _reason(reason) diff --git a/vespalib/src/vespa/vespalib/util/jsonexception.h b/vespalib/src/vespa/vespalib/util/jsonexception.h index e9972740bf9..4e8907fd7cc 100644 --- a/vespalib/src/vespa/vespalib/util/jsonexception.h +++ b/vespalib/src/vespa/vespalib/util/jsonexception.h @@ -8,10 +8,10 @@ namespace vespalib { class JsonStreamException : public Exception { string _reason; public: - JsonStreamException(stringref reason, - stringref history, - stringref location, int skipStack = 0); - stringref getReason() const { return _reason; } + JsonStreamException(std::string_view reason, + std::string_view history, + std::string_view location, int skipStack = 0); + std::string_view getReason() const { return _reason; } VESPA_DEFINE_EXCEPTION_SPINE(JsonStreamException); ~JsonStreamException(); }; diff --git a/vespalib/src/vespa/vespalib/util/jsonstream.cpp b/vespalib/src/vespa/vespalib/util/jsonstream.cpp index 706f64cbdea..bd947c4512f 100644 --- a/vespalib/src/vespa/vespalib/util/jsonstream.cpp +++ b/vespalib/src/vespa/vespalib/util/jsonstream.cpp @@ -14,7 +14,7 @@ JsonStream::StateEntry::StateEntry() noexcept JsonStream::StateEntry::StateEntry(State s) noexcept : state(s), object_key(""), array_index(size_t(0)) {} -JsonStream::StateEntry::StateEntry(State s, stringref key) noexcept +JsonStream::StateEntry::StateEntry(State s, std::string_view key) noexcept : state(s), object_key(key), array_index(size_t(0)) {} JsonStream::StateEntry::StateEntry(const StateEntry &) noexcept = default; @@ -42,7 +42,7 @@ JsonStream::JsonStream(asciistream& as, bool createIndents) JsonStream::~JsonStream() = default; JsonStream& -JsonStream::operator<<(stringref value) +JsonStream::operator<<(std::string_view value) { if (_state.empty()) { fail("Stream already finalized. Can't add a string value."); @@ -366,12 +366,12 @@ JsonStream::getJsonStreamState() const } void -JsonStream::fail(stringref error) const +JsonStream::fail(std::string_view error) const { asciistream report; report << "Invalid state on call: " << error << " (" << getStateString() << ")"; - throw JsonStreamException(report.str(), "", VESPA_STRLOC); + throw JsonStreamException(report.view(), "", VESPA_STRLOC); } } diff --git a/vespalib/src/vespa/vespalib/util/jsonstream.h b/vespalib/src/vespa/vespalib/util/jsonstream.h index 183c8ba046c..ad7e12b03a5 100644 --- a/vespalib/src/vespa/vespalib/util/jsonstream.h +++ b/vespalib/src/vespa/vespalib/util/jsonstream.h @@ -46,7 +46,7 @@ class JsonStream : public JsonStreamTypes { StateEntry() noexcept; StateEntry(State s) noexcept; - StateEntry(State s, stringref key) noexcept; + StateEntry(State s, std::string_view key) noexcept; StateEntry(const StateEntry &) noexcept; StateEntry & operator =(const StateEntry &) noexcept; ~StateEntry(); @@ -65,7 +65,7 @@ public: JsonStream& operator=(JsonStream &&) = default; ~JsonStream(); - JsonStream& operator<<(stringref); + JsonStream& operator<<(std::string_view); JsonStream& operator<<(bool); JsonStream& operator<<(double); JsonStream& operator<<(float); // Less precision that double @@ -86,7 +86,7 @@ public: JsonStream& operator<<(int v) { return operator<<(static_cast<long long>(v)); } JsonStream& operator<<(const char* c) - { return operator<<(stringref(c)); } + { return operator<<(std::string_view(c)); } JsonStream& finalize(); @@ -94,7 +94,7 @@ public: private: string getStateString() const; - void fail(stringref error) const; + void fail(std::string_view error) const; }; } // vespalib diff --git a/vespalib/src/vespa/vespalib/util/jsonwriter.cpp b/vespalib/src/vespa/vespalib/util/jsonwriter.cpp index 65b7ca8268c..dbea2ae7c4b 100644 --- a/vespalib/src/vespa/vespalib/util/jsonwriter.cpp +++ b/vespalib/src/vespa/vespalib/util/jsonwriter.cpp @@ -68,7 +68,7 @@ JSONWriter::quote(const char * str, size_t len) } JSONWriter::JSONWriter() : - _os(NULL), + _os(nullptr), _stack(), _comma(false), _pretty(false), @@ -88,7 +88,7 @@ JSONWriter::JSONWriter(vespalib::asciistream & output) : (*_os) << vespalib::asciistream::Precision(16) << vespalib::forcedot; } -JSONWriter::~JSONWriter() {} +JSONWriter::~JSONWriter() = default; JSONWriter& JSONWriter::setOutputStream(vespalib::asciistream & output) { @@ -173,7 +173,7 @@ JSONWriter::appendNull() } JSONWriter & -JSONWriter::appendKey(stringref str) +JSONWriter::appendKey(std::string_view str) { considerComma(); indent(); @@ -243,7 +243,7 @@ JSONWriter::appendUInt64(uint64_t v) } JSONWriter & -JSONWriter::appendString(stringref str) +JSONWriter::appendString(std::string_view str) { considerComma(); quote(str.data(), str.size()); @@ -252,7 +252,7 @@ JSONWriter::appendString(stringref str) } JSONWriter & -JSONWriter::appendJSON(stringref json) +JSONWriter::appendJSON(std::string_view json) { considerComma(); (*_os) << json; @@ -276,10 +276,15 @@ JSONStringer::clear() return *this; } -JSONStringer::~JSONStringer() { } +JSONStringer::~JSONStringer() = default; -stringref -JSONStringer::toString() const { +std::string_view +JSONStringer::view() const { + return _oss->view(); +} + +std::string +JSONStringer::str() const { return _oss->str(); } diff --git a/vespalib/src/vespa/vespalib/util/jsonwriter.h b/vespalib/src/vespa/vespalib/util/jsonwriter.h index efafd17b987..b00c5432447 100644 --- a/vespalib/src/vespa/vespalib/util/jsonwriter.h +++ b/vespalib/src/vespa/vespalib/util/jsonwriter.h @@ -50,14 +50,14 @@ public: JSONWriter & beginArray(); JSONWriter & endArray(); JSONWriter & appendNull(); - JSONWriter & appendKey(stringref str); + JSONWriter & appendKey(std::string_view str); JSONWriter & appendBool(bool v); JSONWriter & appendDouble(double v); JSONWriter & appendFloat(float v); JSONWriter & appendInt64(int64_t v); JSONWriter & appendUInt64(uint64_t v); - JSONWriter & appendString(stringref str); - JSONWriter & appendJSON(stringref json); + JSONWriter & appendString(std::string_view str); + JSONWriter & appendJSON(std::string_view json); void setPretty() { _pretty = true; }; }; @@ -72,7 +72,8 @@ public: JSONStringer & operator = (JSONStringer &&) = default; ~JSONStringer(); JSONStringer & clear(); - stringref toString() const; + std::string_view view() const; + std::string str() const; }; } diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp index e6a00f4b86d..49b875463a7 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp @@ -15,13 +15,13 @@ namespace fs = std::filesystem; namespace vespalib::alloc { -MmapFileAllocator::MmapFileAllocator(const vespalib::string& dir_name) - : MmapFileAllocator(dir_name, default_small_limit, default_premmap_size) +MmapFileAllocator::MmapFileAllocator(vespalib::string dir_name) + : MmapFileAllocator(std::move(dir_name), default_small_limit, default_premmap_size) { } -MmapFileAllocator::MmapFileAllocator(const vespalib::string& dir_name, uint32_t small_limit, uint32_t premmap_size) - : _dir_name(dir_name), +MmapFileAllocator::MmapFileAllocator(vespalib::string dir_name, uint32_t small_limit, uint32_t premmap_size) + : _dir_name(std::move(dir_name)), _small_limit(small_limit), _premmap_size(premmap_size), _file(_dir_name + "/swapfile"), diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h index f568a14572a..ee310af9cff 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h @@ -51,8 +51,8 @@ class MmapFileAllocator : public MemoryAllocator { public: static constexpr uint32_t default_small_limit = 128_Ki; static constexpr uint32_t default_premmap_size = 1_Mi; - explicit MmapFileAllocator(const vespalib::string& dir_name); - MmapFileAllocator(const vespalib::string& dir_name, uint32_t small_limit, uint32_t premmap_size); + explicit MmapFileAllocator(vespalib::string dir_name); + MmapFileAllocator(vespalib::string dir_name, uint32_t small_limit, uint32_t premmap_size); ~MmapFileAllocator() override; PtrAndSize alloc(size_t sz) const override; void free(PtrAndSize alloc) const noexcept override; diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator_factory.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator_factory.cpp index d52a924dbe3..2c99eabfdc3 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator_factory.cpp +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator_factory.cpp @@ -13,9 +13,7 @@ MmapFileAllocatorFactory::MmapFileAllocatorFactory() { } -MmapFileAllocatorFactory::~MmapFileAllocatorFactory() -{ -} +MmapFileAllocatorFactory::~MmapFileAllocatorFactory() = default; void MmapFileAllocatorFactory::setup(const vespalib::string& dir_name) diff --git a/vespalib/src/vespa/vespalib/util/printable.cpp b/vespalib/src/vespa/vespalib/util/printable.cpp index 14c31a5cf7a..4b3ce8b11e3 100644 --- a/vespalib/src/vespa/vespalib/util/printable.cpp +++ b/vespalib/src/vespa/vespalib/util/printable.cpp @@ -30,7 +30,7 @@ AsciiPrintable::print(std::ostream& out, bool verbose, { vespalib::asciistream as; print(as, PrintProperties(verbose ? VERBOSE : NORMAL, indent)); - out << as.str(); + out << as.view(); } vespalib::string diff --git a/vespalib/src/vespa/vespalib/util/printable.h b/vespalib/src/vespa/vespalib/util/printable.h index 1ae3be8d3fa..ed3da18619a 100644 --- a/vespalib/src/vespa/vespalib/util/printable.h +++ b/vespalib/src/vespa/vespalib/util/printable.h @@ -103,7 +103,7 @@ public: vespalib::string _indent; public: - PrintProperties(PrintMode mode = NORMAL, stringref indent_ = "") + PrintProperties(PrintMode mode = NORMAL, std::string_view indent_ = "") : _mode(mode), _indent(indent_) {} PrintProperties indentedCopy() const diff --git a/vespalib/src/vespa/vespalib/util/printable.hpp b/vespalib/src/vespa/vespalib/util/printable.hpp index 71fccf28757..21794039e7c 100644 --- a/vespalib/src/vespa/vespalib/util/printable.hpp +++ b/vespalib/src/vespa/vespalib/util/printable.hpp @@ -13,7 +13,7 @@ void print(const std::vector<T> & v, vespalib::asciistream& out, const AsciiPrin } vespalib::asciistream ost; ost << v[0]; - bool newLineBetweenEntries = (ost.str().size() > 15); + bool newLineBetweenEntries = (ost.view().size() > 15); out << "["; for (size_t i=0; i<v.size(); ++i) { if (i != 0) out << ","; diff --git a/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp b/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp index 38f047c5d3b..57dfb7c9669 100644 --- a/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp +++ b/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp @@ -24,7 +24,7 @@ namespace { */ bool -isRange(vespalib::stringref line) { +isRange(std::string_view line) { for (char c : line) { if (c == ' ') { return true; @@ -51,7 +51,7 @@ isRange(vespalib::stringref line) { */ bool -isAnonymous(vespalib::stringref line) { +isAnonymous(std::string_view line) { int delims = 0; for (char c : line) { if (delims >= 4) { @@ -78,8 +78,8 @@ isAnonymous(vespalib::stringref line) { * mapped pages. */ -vespalib::stringref -getLineHeader(vespalib::stringref line) +std::string_view +getLineHeader(std::string_view line) { return line.substr(0, line.find(':')); } @@ -97,12 +97,12 @@ ProcessMemoryStats::createStatsFromSmaps() uint64_t lineVal = 0; while (!smaps.eof()) { string backedLine = smaps.getline(); - stringref line(backedLine); + std::string_view line(backedLine); if (isRange(line)) { ret._mappings_count += 1; anonymous = isAnonymous(line); } else if (!line.empty()) { - stringref lineHeader = getLineHeader(line); + std::string_view lineHeader = getLineHeader(line); if (lineHeader == "Size") { asciistream is(line.substr(lineHeader.size() + 1)); is >> lineVal; diff --git a/vespalib/src/vespa/vespalib/util/regexp.cpp b/vespalib/src/vespa/vespalib/util/regexp.cpp index 831de5cc710..0ad00374f07 100644 --- a/vespalib/src/vespa/vespalib/util/regexp.cpp +++ b/vespalib/src/vespa/vespalib/util/regexp.cpp @@ -14,7 +14,7 @@ namespace vespalib { namespace { -bool has_option(vespalib::stringref re) { +bool has_option(std::string_view re) { return (re.find('|') != re.npos); } @@ -27,7 +27,7 @@ bool maybe_none(char c) { const vespalib::string special("^|()[]{}.*?+\\$"); bool is_special(char c) { return special.find(c) != special.npos; } -vespalib::string escape(vespalib::stringref str) { +vespalib::string escape(std::string_view str) { vespalib::string result; for (char c: str) { if (is_special(c)) { @@ -41,7 +41,7 @@ vespalib::string escape(vespalib::stringref str) { } // namespace vespalib::<unnamed> vespalib::string -RegexpUtil::get_prefix(vespalib::stringref re) +RegexpUtil::get_prefix(std::string_view re) { vespalib::string prefix; if ((re.size() > 0) && (re.data()[0] == '^') && !has_option(re)) { @@ -58,13 +58,13 @@ RegexpUtil::get_prefix(vespalib::stringref re) } vespalib::string -RegexpUtil::make_from_suffix(vespalib::stringref suffix) +RegexpUtil::make_from_suffix(std::string_view suffix) { return escape(suffix) + "$"; } vespalib::string -RegexpUtil::make_from_substring(vespalib::stringref substring) +RegexpUtil::make_from_substring(std::string_view substring) { return escape(substring); } diff --git a/vespalib/src/vespa/vespalib/util/regexp.h b/vespalib/src/vespa/vespalib/util/regexp.h index 862a3ca3e48..6c4eb3026dd 100644 --- a/vespalib/src/vespa/vespalib/util/regexp.h +++ b/vespalib/src/vespa/vespalib/util/regexp.h @@ -21,7 +21,7 @@ public: * @param re Regular expression. * @return prefix that must be present in matching strings **/ - static vespalib::string get_prefix(vespalib::stringref re); + static vespalib::string get_prefix(std::string_view re); /** * Make a regexp matching strings with the given suffix. @@ -29,7 +29,7 @@ public: * @param suffix the suffix * @return the regexp **/ - static vespalib::string make_from_suffix(vespalib::stringref suffix); + static vespalib::string make_from_suffix(std::string_view suffix); /** * Make a regexp matching strings with the given substring. @@ -37,7 +37,7 @@ public: * @param substring the substring * @return the regexp **/ - static vespalib::string make_from_substring(vespalib::stringref substring); + static vespalib::string make_from_substring(std::string_view substring); }; } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/util/shared_string_repo.cpp b/vespalib/src/vespa/vespalib/util/shared_string_repo.cpp index 09f2bbd828d..1f0083ce668 100644 --- a/vespalib/src/vespa/vespalib/util/shared_string_repo.cpp +++ b/vespalib/src/vespa/vespalib/util/shared_string_repo.cpp @@ -197,7 +197,7 @@ SharedStringRepo::stats() namespace { uint32_t -try_make_direct_id(vespalib::stringref str) noexcept { +try_make_direct_id(std::string_view str) noexcept { if ((str.size() > SharedStringRepo::FAST_DIGITS) || ((str.size() > 1) && (str[0] == '0'))) { return SharedStringRepo::ID_BIAS; } else if (str.empty()) { @@ -229,7 +229,7 @@ string_from_direct_id(uint32_t id) { } string_id -SharedStringRepo::resolve(vespalib::stringref str) { +SharedStringRepo::resolve(std::string_view str) { uint32_t direct_id = try_make_direct_id(str); if (direct_id >= ID_BIAS) { uint64_t full_hash = xxhash::xxh3_64(str.data(), str.size()); @@ -276,7 +276,7 @@ SharedStringRepo::Handle SharedStringRepo::Handle::handle_from_number_slow(int64_t value) { char buf[24]; auto res = std::to_chars(buf, buf + sizeof(buf), value, 10); - return Handle(vespalib::stringref(buf, res.ptr - buf)); + return Handle(std::string_view(buf, res.ptr - buf)); } SharedStringRepo::Handles::Handles() diff --git a/vespalib/src/vespa/vespalib/util/shared_string_repo.h b/vespalib/src/vespa/vespalib/util/shared_string_repo.h index fded3621803..abf51e5fa49 100644 --- a/vespalib/src/vespa/vespalib/util/shared_string_repo.h +++ b/vespalib/src/vespa/vespalib/util/shared_string_repo.h @@ -50,7 +50,7 @@ private: static const bool should_reclaim; struct AltKey { - vespalib::stringref str; + std::string_view str; uint32_t hash; }; @@ -132,7 +132,7 @@ private: SharedStringRepo(); ~SharedStringRepo(); - string_id resolve(vespalib::stringref str); + string_id resolve(std::string_view str); vespalib::string as_string(string_id id); string_id copy(string_id id); void reclaim(string_id id); @@ -150,7 +150,7 @@ public: static Handle handle_from_number_slow(int64_t value); public: Handle() noexcept : _id() {} - explicit Handle(vespalib::stringref str) : _id(_repo.resolve(str)) {} + explicit Handle(std::string_view str) : _id(_repo.resolve(str)) {} Handle(const Handle &rhs) : _id(_repo.copy(rhs._id)) {} Handle &operator=(const Handle &rhs) { string_id copy = _repo.copy(rhs._id); @@ -196,7 +196,7 @@ public: Handles &operator=(const Handles &) = delete; Handles &operator=(Handles &&) = delete; ~Handles(); - string_id add(vespalib::stringref str) { + string_id add(std::string_view str) { string_id id = _repo.resolve(str); _handles.push_back(id); return id; diff --git a/vespalib/src/vespa/vespalib/util/static_string.h b/vespalib/src/vespa/vespalib/util/static_string.h index d4246363f3e..89eaba13fa1 100644 --- a/vespalib/src/vespa/vespalib/util/static_string.h +++ b/vespalib/src/vespa/vespalib/util/static_string.h @@ -24,13 +24,12 @@ private: public: constexpr std::string_view view() const noexcept { return _view; } constexpr operator std::string_view() const noexcept { return _view; } - vespalib::stringref ref() const noexcept { return {_view.data(), _view.size()}; } - operator vespalib::stringref() const noexcept { return ref(); } + std::string_view ref() const noexcept { return {_view.data(), _view.size()}; } }; namespace literals { constexpr StaticStringView operator "" _ssv(const char *literal, size_t size) { - return vespalib::StaticStringView(literal, size); + return {literal, size}; } } // literals diff --git a/vespalib/src/vespa/vespalib/util/string_escape.cpp b/vespalib/src/vespa/vespalib/util/string_escape.cpp index 56ea640681d..5487598a564 100644 --- a/vespalib/src/vespa/vespalib/util/string_escape.cpp +++ b/vespalib/src/vespa/vespalib/util/string_escape.cpp @@ -24,7 +24,7 @@ std::vector<bool> precompute_escaped_xml_chars() { std::vector<bool> escaped_xml_chars = precompute_escaped_xml_chars(); template <typename StreamT> -void do_write_xml_content_escaped(StreamT& out, vespalib::stringref str) { +void do_write_xml_content_escaped(StreamT& out, std::string_view str) { for (const char s : str) { if (escaped_xml_chars[static_cast<uint8_t>(s)]) { if (s == '<') out << "<"; @@ -41,7 +41,7 @@ void do_write_xml_content_escaped(StreamT& out, vespalib::stringref str) { } -vespalib::string xml_attribute_escaped(vespalib::stringref str) { +vespalib::string xml_attribute_escaped(std::string_view str) { vespalib::asciistream ost; for (const char s : str) { if (s == '"' || s == '\'' || s == '\n' @@ -62,17 +62,17 @@ vespalib::string xml_attribute_escaped(vespalib::stringref str) { return ost.str(); } -vespalib::string xml_content_escaped(vespalib::stringref str) { +vespalib::string xml_content_escaped(std::string_view str) { vespalib::asciistream out; do_write_xml_content_escaped(out, str); return out.str(); } -void write_xml_content_escaped(vespalib::asciistream& out, vespalib::stringref str) { +void write_xml_content_escaped(vespalib::asciistream& out, std::string_view str) { do_write_xml_content_escaped(out, str); } -void write_xml_content_escaped(std::ostream& out, vespalib::stringref str) { +void write_xml_content_escaped(std::ostream& out, std::string_view str) { do_write_xml_content_escaped(out, str); } diff --git a/vespalib/src/vespa/vespalib/util/string_escape.h b/vespalib/src/vespa/vespalib/util/string_escape.h index fef7ed31f7e..bc394e8d216 100644 --- a/vespalib/src/vespa/vespalib/util/string_escape.h +++ b/vespalib/src/vespa/vespalib/util/string_escape.h @@ -12,15 +12,15 @@ namespace vespalib { * - all control chars < char value 32 * - <, >, &, " and ' */ -[[nodiscard]] vespalib::string xml_attribute_escaped(vespalib::stringref s); +[[nodiscard]] vespalib::string xml_attribute_escaped(std::string_view s); /** * Returns input string but where the following characters are escaped: * - all control chars < char value 32, _except_ linebreak * - <, > and & */ -[[nodiscard]] vespalib::string xml_content_escaped(vespalib::stringref s); -void write_xml_content_escaped(vespalib::asciistream& out, vespalib::stringref s); -void write_xml_content_escaped(std::ostream& out, vespalib::stringref s); +[[nodiscard]] vespalib::string xml_content_escaped(std::string_view s); +void write_xml_content_escaped(vespalib::asciistream& out, std::string_view s); +void write_xml_content_escaped(std::ostream& out, std::string_view s); } diff --git a/vespalib/src/vespa/vespalib/util/string_hash.cpp b/vespalib/src/vespa/vespalib/util/string_hash.cpp index bf8577a76a4..ecc1d1c969e 100644 --- a/vespalib/src/vespa/vespalib/util/string_hash.cpp +++ b/vespalib/src/vespa/vespalib/util/string_hash.cpp @@ -17,7 +17,7 @@ double hash2d(const char *str, size_t len) { return d; } -double hash2d(vespalib::stringref str) { +double hash2d(std::string_view str) { return hash2d(str.data(), str.size()); } diff --git a/vespalib/src/vespa/vespalib/util/string_hash.h b/vespalib/src/vespa/vespalib/util/string_hash.h index 8d7fe125cf7..7f9558fe310 100644 --- a/vespalib/src/vespa/vespalib/util/string_hash.h +++ b/vespalib/src/vespa/vespalib/util/string_hash.h @@ -10,7 +10,7 @@ namespace vespalib { * simple string hashing function similar to the one used by Java. **/ double hash2d(const char *str, size_t len); -double hash2d(vespalib::stringref str); +double hash2d(std::string_view str); } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/util/xmlstream.cpp b/vespalib/src/vespa/vespalib/util/xmlstream.cpp index e73ca028ae2..90833507ee7 100644 --- a/vespalib/src/vespa/vespalib/util/xmlstream.cpp +++ b/vespalib/src/vespa/vespalib/util/xmlstream.cpp @@ -339,7 +339,7 @@ XmlAttribute::XmlAttribute(const std::string& name, const char * value, uint32_t vespalib::asciistream ost; if (flags & HEX) ost << vespalib::hex << "0x"; ost << value; - _value = ost.str(); + _value = ost.view(); if (!isLegalName(name)) { throw vespalib::IllegalArgumentException("Name '" + name + "' contains " "illegal XML characters and cannot be used as attribute name"); @@ -402,7 +402,7 @@ using ConstCharP = const char *; template XmlAttribute::XmlAttribute(const std::string &, std::string, unsigned int); template XmlAttribute::XmlAttribute(const std::string &, vespalib::string, unsigned int); -template XmlAttribute::XmlAttribute(const std::string &, vespalib::stringref, unsigned int); +template XmlAttribute::XmlAttribute(const std::string &, std::string_view, unsigned int); template XmlAttribute::XmlAttribute(const std::string &, CharP, unsigned int); template XmlAttribute::XmlAttribute(const std::string &, bool, unsigned int); template XmlAttribute::XmlAttribute(const std::string &, short, unsigned int); |