diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-10 21:28:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-10 21:28:52 +0100 |
commit | 2263b7665b47555014e2dda46b94d8f065cf4504 (patch) | |
tree | f64f53a1a187120364996178ba8152a873bda63d | |
parent | 5892f95fc68a3571efe0c343f32b3aa90b42dc8e (diff) | |
parent | d0ef2917614c45fe58c6e9df884fd9caa7631bf0 (diff) |
Merge pull request #21639 from vespa-engine/balder/balder/reduce-code-visibility-2
Reduce exposure of SymbolTable, Stash and other classes not necessary…
21 files changed, 154 insertions, 87 deletions
diff --git a/eval/src/tests/tensor/binary_format/binary_format_test.cpp b/eval/src/tests/tensor/binary_format/binary_format_test.cpp index bec62b0e0a6..fa3b333dc72 100644 --- a/eval/src/tests/tensor/binary_format/binary_format_test.cpp +++ b/eval/src/tests/tensor/binary_format/binary_format_test.cpp @@ -11,6 +11,7 @@ #include <vespa/vespalib/io/mapped_file_input.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/vespalib/util/stash.h> #include <vespa/vespalib/gtest/gtest.h> using namespace vespalib; diff --git a/fnet/src/vespa/fnet/frt/rpcrequest.h b/fnet/src/vespa/fnet/frt/rpcrequest.h index d582f7cfbcb..a095c274687 100644 --- a/fnet/src/vespa/fnet/frt/rpcrequest.h +++ b/fnet/src/vespa/fnet/frt/rpcrequest.h @@ -8,7 +8,6 @@ #include <vespa/vespalib/util/stash.h> #include <atomic> -class FNETConnection; class FNET_Packet; class FRT_IAbortHandler diff --git a/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp b/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp index aa55d61e628..a02e98a93b8 100644 --- a/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp +++ b/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <chrono> #include <vespa/vespalib/gtest/gtest.h> namespace storage::distributor { diff --git a/vespalib/src/tests/slime/slime_test.cpp b/vespalib/src/tests/slime/slime_test.cpp index cd80fa9b984..1f822f9dd6f 100644 --- a/vespalib/src/tests/slime/slime_test.cpp +++ b/vespalib/src/tests/slime/slime_test.cpp @@ -6,6 +6,8 @@ #include <vespa/vespalib/data/slime/array_value.h> #include <vespa/vespalib/data/slime/strfmt.h> #include <vespa/vespalib/data/simple_buffer.h> +#include <vespa/vespalib/data/slime/symbol_table.h> +#include <vespa/vespalib/data/slime/basic_value.h> #include <type_traits> #include <vespa/log/log.h> diff --git a/vespalib/src/vespa/vespalib/data/slime/basic_value.h b/vespalib/src/vespa/vespalib/data/slime/basic_value.h index 43adc39be60..4221c0622a5 100644 --- a/vespalib/src/vespa/vespalib/data/slime/basic_value.h +++ b/vespalib/src/vespa/vespalib/data/slime/basic_value.h @@ -3,7 +3,6 @@ #pragma once #include "value.h" -#include "memory.h" #include <vespa/vespalib/util/traits.h> namespace vespalib { class Stash; } diff --git a/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.cpp b/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.cpp index db9c21ba0a6..4655f1c36c9 100644 --- a/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.cpp @@ -1,7 +1,34 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "basic_value_factory.h" +#include "basic_value.h" +#include <vespa/vespalib/util/stash.h> namespace vespalib::slime { -} // namespace vespalib::slime +Value * +BoolValueFactory::create(Stash & stash) const { + return & stash.create<BasicBoolValue>(input); +} + +Value * +LongValueFactory::create(Stash & stash) const { + return & stash.create<BasicLongValue>(input); +} + +Value * +DoubleValueFactory::create(Stash & stash) const { + return & stash.create<BasicDoubleValue>(input); +} + +Value * +StringValueFactory::create(Stash & stash) const { + return & stash.create<BasicStringValue>(input, stash); +} + +Value * +DataValueFactory::create(Stash & stash) const { + return & stash.create<BasicDataValue>(input, stash); +} + +} diff --git a/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.h b/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.h index 4fa10fa70f1..451e3fa48cb 100644 --- a/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.h +++ b/vespalib/src/vespa/vespalib/data/slime/basic_value_factory.h @@ -3,39 +3,38 @@ #pragma once #include "value_factory.h" -#include "basic_value.h" -#include <vespa/vespalib/util/stash.h> +#include <vespa/vespalib/data/memory.h> namespace vespalib::slime { struct BoolValueFactory final : public ValueFactory { bool input; BoolValueFactory(bool in) noexcept : input(in) {} - Value *create(Stash & stash) const override { return & stash.create<BasicBoolValue>(input); } + Value *create(Stash & stash) const override; }; struct LongValueFactory final : public ValueFactory { int64_t input; LongValueFactory(int64_t in) noexcept : input(in) {} - Value *create(Stash & stash) const override { return & stash.create<BasicLongValue>(input); } + Value *create(Stash & stash) const override; }; struct DoubleValueFactory final : public ValueFactory { double input; DoubleValueFactory(double in) noexcept : input(in) {} - Value *create(Stash & stash) const override { return & stash.create<BasicDoubleValue>(input); } + Value *create(Stash & stash) const override; }; struct StringValueFactory final : public ValueFactory { Memory input; StringValueFactory(Memory in) noexcept : input(in) {} - Value *create(Stash & stash) const override { return & stash.create<BasicStringValue>(input, stash); } + Value *create(Stash & stash) const override; }; struct DataValueFactory final : public ValueFactory { Memory input; DataValueFactory(Memory in) noexcept : input(in) {} - Value *create(Stash & stash) const override { return & stash.create<BasicDataValue>(input, stash); } + Value *create(Stash & stash) const override; }; } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.cpp b/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.cpp index a96da032b85..1bb1c642438 100644 --- a/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.cpp @@ -3,9 +3,12 @@ #include "external_data_value_factory.h" #include "external_data_value.h" #include "basic_value.h" +#include <vespa/vespalib/util/stash.h> namespace vespalib::slime { +ExternalDataValueFactory::~ExternalDataValueFactory() = default; + Value * ExternalDataValueFactory::create(Stash &stash) const { diff --git a/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.h b/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.h index b8a85f63084..8d68b430684 100644 --- a/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.h +++ b/vespalib/src/vespa/vespalib/data/slime/external_data_value_factory.h @@ -3,17 +3,19 @@ #pragma once #include "value_factory.h" -#include "external_memory.h" -#include <vespa/vespalib/util/stash.h> +#include <memory> namespace vespalib::slime { +class ExternalMemory; + /** * Value factory for data values using external memory. **/ struct ExternalDataValueFactory : public ValueFactory { - mutable ExternalMemory::UP input; - ExternalDataValueFactory(ExternalMemory::UP in) : input(std::move(in)) {} + mutable std::unique_ptr<ExternalMemory> input; + ExternalDataValueFactory(std::unique_ptr<ExternalMemory> in) : input(std::move(in)) {} + ~ExternalDataValueFactory() override; Value *create(Stash &stash) const override; }; diff --git a/vespalib/src/vespa/vespalib/data/slime/json_format.h b/vespalib/src/vespa/vespalib/data/slime/json_format.h index fcb3b9d448d..d1e52107526 100644 --- a/vespalib/src/vespa/vespalib/data/slime/json_format.h +++ b/vespalib/src/vespa/vespalib/data/slime/json_format.h @@ -2,8 +2,8 @@ #pragma once -#include <vespa/vespalib/data/output.h> #include "type.h" +#include <vespa/vespalib/data/output.h> #include <vespa/vespalib/data/input_reader.h> #include <vespa/vespalib/data/output_writer.h> diff --git a/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.cpp b/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.cpp index 6905b7034c7..584ec86fe2c 100644 --- a/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.cpp @@ -1,7 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "named_symbol_inserter.h" +#include "symbol_table.h" namespace vespalib::slime { +Symbol +NamedSymbolInserter::insert() { + return _table.insert(_name); +} } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.h b/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.h index e8bc939332a..0910e0d90e1 100644 --- a/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.h +++ b/vespalib/src/vespa/vespalib/data/slime/named_symbol_inserter.h @@ -3,10 +3,13 @@ #pragma once #include "symbol_inserter.h" -#include "symbol_table.h" + +namespace vespalib { class Memory; } namespace vespalib::slime { +class SymbolTable; + /** * Class used to insert the name of a field into a symbol table. **/ @@ -19,9 +22,7 @@ private: public: NamedSymbolInserter(SymbolTable &table, const Memory &name) noexcept : _table(table), _name(name) {} - Symbol insert() override { - return _table.insert(_name); - } + Symbol insert() override; }; } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.cpp b/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.cpp index 4a0a129ebff..05c6fff67c9 100644 --- a/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.cpp @@ -1,7 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "named_symbol_lookup.h" +#include "symbol_table.h" namespace vespalib::slime { +Symbol +NamedSymbolLookup::lookup() const { + return _table.lookup(_name); +} + } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.h b/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.h index 685592039cf..6c38551ee72 100644 --- a/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.h +++ b/vespalib/src/vespa/vespalib/data/slime/named_symbol_lookup.h @@ -3,10 +3,13 @@ #pragma once #include "symbol_lookup.h" -#include "symbol_table.h" + +namespace vespalib { class Memory; } namespace vespalib::slime { +class SymbolTable; + /** * Class used to look up the name of a field in a symbol table. **/ @@ -19,9 +22,7 @@ private: public: NamedSymbolLookup(const SymbolTable &table, const Memory &name) : _table(table), _name(name) {} - Symbol lookup() const override { - return _table.lookup(_name); - } + Symbol lookup() const override; }; } // namespace vespalib::slime diff --git a/vespalib/src/vespa/vespalib/data/slime/object_value.cpp b/vespalib/src/vespa/vespalib/data/slime/object_value.cpp index e8434834d9c..b4bffe4bf00 100644 --- a/vespalib/src/vespa/vespalib/data/slime/object_value.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/object_value.cpp @@ -6,6 +6,7 @@ #include "resolved_symbol.h" #include "named_symbol_lookup.h" #include "named_symbol_inserter.h" +#include "symbol_table.h" namespace vespalib::slime { diff --git a/vespalib/src/vespa/vespalib/data/slime/root_value.h b/vespalib/src/vespa/vespalib/data/slime/root_value.h index b61325e9cd0..1a7f8115015 100644 --- a/vespalib/src/vespa/vespalib/data/slime/root_value.h +++ b/vespalib/src/vespa/vespalib/data/slime/root_value.h @@ -14,21 +14,21 @@ private: Stash *_stash; public: - RootValue(Stash * stash) : _value(NixValue::instance()), _stash(stash) {} - RootValue(RootValue && rhs) : _value(rhs._value), _stash(rhs._stash) { + RootValue(Stash * stash) noexcept : _value(NixValue::instance()), _stash(stash) {} + RootValue(RootValue && rhs) noexcept : _value(rhs._value), _stash(rhs._stash) { rhs._value = NixValue::instance(); rhs._stash = nullptr; } RootValue(const RootValue &) = delete; RootValue &operator=(const RootValue &) = delete; - RootValue &operator=(RootValue && rhs) { + RootValue &operator=(RootValue && rhs) noexcept { _value = rhs._value; _stash = rhs._stash; rhs._value = NixValue::instance(); rhs._stash = nullptr; return *this; } - Cursor &get() const { return *_value; } + Cursor &get() const noexcept { return *_value; } Cursor &set(const ValueFactory &input) { Value *value = input.create(*_stash); _value = value; diff --git a/vespalib/src/vespa/vespalib/data/slime/slime.cpp b/vespalib/src/vespa/vespalib/data/slime/slime.cpp index 3afcb192f9d..d6fac44b360 100644 --- a/vespalib/src/vespa/vespalib/data/slime/slime.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/slime.cpp @@ -1,12 +1,59 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "slime.h" +#include "symbol_table.h" +#include <vespa/vespalib/util/stash.h> namespace vespalib { -Slime::~Slime() { } +Slime::Params::Params() : Params(std::make_unique<SymbolTable>()) { } +Slime::Params::Params(std::unique_ptr<SymbolTable> symbols) noexcept : _symbols(std::move(symbols)), _chunkSize(4096) { } +Slime::Params::Params(Params &&) noexcept = default; +Slime::Params::~Params() = default; -bool operator == (const Slime & a, const Slime & b) +std::unique_ptr<slime::SymbolTable> +Slime::Params::detachSymbols() { + return std::move(_symbols); +} + +Slime::Slime(Params params) + : _names(params.detachSymbols()), + _stash(std::make_unique<Stash>(params.getChunkSize())), + _root(_stash.get()) +{ } + +Slime::Slime(Slime &&rhs) noexcept = default; +Slime & Slime::operator=(Slime &&rhs) noexcept = default; +Slime::~Slime() = default; + +std::unique_ptr<slime::SymbolTable> +Slime::reclaimSymbols(Slime &&rhs) { + rhs._stash.reset(); + rhs._root = RootValue(nullptr); + return std::move(rhs._names); +} + +size_t +Slime::symbols() const noexcept { + return _names->symbols(); +} + +Memory +Slime::inspect(Symbol symbol) const { + return _names->inspect(symbol); +} + +slime::Symbol +Slime::insert(Memory name) { + return _names->insert(name); +} + +slime::Symbol +Slime::lookup(Memory name) const { + return _names->lookup(name); +} + +bool operator == (const Slime & a, const Slime & b) noexcept { return a.get() == b.get(); } diff --git a/vespalib/src/vespa/vespalib/data/slime/slime.h b/vespalib/src/vespa/vespalib/data/slime/slime.h index 6a977b009a4..028133d7be1 100644 --- a/vespalib/src/vespa/vespalib/data/slime/slime.h +++ b/vespalib/src/vespa/vespalib/data/slime/slime.h @@ -3,7 +3,6 @@ #pragma once #include "array_traverser.h" -#include "basic_value.h" #include "basic_value_factory.h" #include "binary_format.h" #include "convenience.h" @@ -22,7 +21,6 @@ #include "symbol.h" #include "symbol_inserter.h" #include "symbol_lookup.h" -#include "symbol_table.h" #include "type.h" #include "value.h" #include "value_factory.h" @@ -53,79 +51,54 @@ private: typedef slime::Cursor Cursor; typedef slime::Inspector Inspector; - SymbolTable::UP _names; - Stash::UP _stash; - RootValue _root; + std::unique_ptr<SymbolTable> _names; + std::unique_ptr<Stash> _stash; + RootValue _root; public: typedef std::unique_ptr<Slime> UP; class Params { private: - SymbolTable::UP _symbols; - size_t _chunkSize; + std::unique_ptr<SymbolTable> _symbols; + size_t _chunkSize; public: - Params() : Params(std::make_unique<SymbolTable>()) { } - explicit Params(SymbolTable::UP symbols) : _symbols(std::move(symbols)), _chunkSize(4096) { } + Params(); + explicit Params(std::unique_ptr<SymbolTable> symbols) noexcept; + Params(Params &&) noexcept; + ~Params(); Params & setChunkSize(size_t chunkSize) { _chunkSize = chunkSize; return *this; } size_t getChunkSize() const { return _chunkSize; } - SymbolTable::UP detachSymbols() { return std::move(_symbols); } + std::unique_ptr<SymbolTable> detachSymbols(); }; /** * Construct an initially empty Slime object. **/ - explicit Slime(Params params = Params()) : - _names(params.detachSymbols()), - _stash(std::make_unique<Stash>(params.getChunkSize())), - _root(_stash.get()) - { } + explicit Slime(Params params = Params()); ~Slime(); - Slime(Slime &&rhs) noexcept : - _names(std::move(rhs._names)), - _stash(std::move(rhs._stash)), - _root(std::move(rhs._root)) - { - } + Slime(Slime &&rhs) noexcept; + Slime &operator=(Slime &&rhs) noexcept; Slime(const Slime & rhs) = delete; Slime& operator = (const Slime & rhs) = delete; - static SymbolTable::UP reclaimSymbols(Slime &&rhs) { - rhs._stash.reset(); - rhs._root = RootValue(nullptr); - return std::move(rhs._names); - } - - Slime &operator=(Slime &&rhs) { - _names = std::move(rhs._names); - _stash = std::move(rhs._stash); - _root = std::move(rhs._root); - return *this; - } + static std::unique_ptr<SymbolTable> reclaimSymbols(Slime &&rhs); - size_t symbols() const { - return _names->symbols(); - } + size_t symbols() const noexcept; - Memory inspect(Symbol symbol) const { - return _names->inspect(symbol); - } + Memory inspect(Symbol symbol) const; - Symbol insert(Memory name) { - return _names->insert(name); - } + Symbol insert(Memory name); - Symbol lookup(Memory name) const { - return _names->lookup(name); - } + Symbol lookup(Memory name) const; - Cursor &get() { return _root.get(); } + Cursor &get() noexcept { return _root.get(); } - Inspector &get() const { return _root.get(); } + Inspector &get() const noexcept { return _root.get(); } template <typename ID> Inspector &operator[](ID id) const { return get()[id]; } @@ -177,7 +150,7 @@ public: vespalib::string toString() const { return get().toString(); } }; -bool operator == (const Slime & a, const Slime & b); +bool operator == (const Slime & a, const Slime & b) noexcept; std::ostream & operator << (std::ostream & os, const Slime & slime); } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/data/slime/symbol_table.h b/vespalib/src/vespa/vespalib/data/slime/symbol_table.h index 40200faaca7..2ad983b140c 100644 --- a/vespalib/src/vespa/vespalib/data/slime/symbol_table.h +++ b/vespalib/src/vespa/vespalib/data/slime/symbol_table.h @@ -29,7 +29,7 @@ public: typedef std::unique_ptr<SymbolTable> UP; SymbolTable(size_t expectedNumSymbols=16); ~SymbolTable(); - size_t symbols() const { return _names.size(); } + size_t symbols() const noexcept { return _names.size(); } Memory inspect(const Symbol &symbol) const { if (symbol.getValue() > _names.size()) { return Memory(); diff --git a/vespalib/src/vespa/vespalib/data/slime/type.h b/vespalib/src/vespa/vespalib/data/slime/type.h index 915e80ca7f7..50789d3f53b 100644 --- a/vespalib/src/vespa/vespalib/data/slime/type.h +++ b/vespalib/src/vespa/vespalib/data/slime/type.h @@ -15,10 +15,10 @@ private: uint32_t _id; protected: - Type(uint32_t id) : _id(id) {} + Type(uint32_t id) noexcept : _id(id) {} public: - uint32_t getId() const { return _id; } + uint32_t getId() const noexcept { return _id; } }; /** diff --git a/vespalib/src/vespa/vespalib/util/stash.h b/vespalib/src/vespa/vespalib/util/stash.h index 50945bf3cf2..11731e69217 100644 --- a/vespalib/src/vespa/vespalib/util/stash.h +++ b/vespalib/src/vespa/vespalib/util/stash.h @@ -48,9 +48,9 @@ struct Chunk { Chunk *next; size_t used; Chunk(const Chunk &) = delete; - explicit Chunk(Chunk *next_in) : next(next_in), used(sizeof(Chunk)) {} - void clear() { used = sizeof(Chunk); } - char *alloc(size_t size, size_t chunk_size) { + explicit Chunk(Chunk *next_in) noexcept : next(next_in), used(sizeof(Chunk)) {} + void clear() noexcept { used = sizeof(Chunk); } + char *alloc(size_t size, size_t chunk_size) noexcept { size_t aligned_size = ((size + (sizeof(char *) - 1)) & ~(sizeof(char *) - 1)); if (used + aligned_size > chunk_size) { @@ -84,7 +84,7 @@ private: size_t _chunk_size; char *do_alloc(size_t size); - bool is_small(size_t size) const { return (size < (_chunk_size / 4)); } + bool is_small(size_t size) const noexcept { return (size < (_chunk_size / 4)); } template <typename T, typename ... Args> T *init_array(char *mem, size_t size, Args && ... args) { @@ -119,10 +119,10 @@ public: stash::Cleanup *_cleanup; stash::Chunk *_chunk; size_t _used; - Mark(stash::Cleanup *cleanup, stash::Chunk *chunk) + Mark(stash::Cleanup *cleanup, stash::Chunk *chunk) noexcept : _cleanup(cleanup), _chunk(chunk), _used(chunk ? chunk->used : 0u) {} public: - Mark() : Mark(nullptr, nullptr) {} + Mark() noexcept : Mark(nullptr, nullptr) {} }; typedef std::unique_ptr<Stash> UP; @@ -137,7 +137,7 @@ public: void clear(); - Mark mark() const { return Mark(_cleanup, _chunks); } + Mark mark() const noexcept { return Mark(_cleanup, _chunks); } void revert(const Mark &mark); size_t count_used() const; |