summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-03-20 12:52:53 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-03-20 12:52:53 +0000
commitc12fe9e1f77a2d2d7dfbcd846bda7310c198734f (patch)
treee2c494a85b0a37d935b97d008abacae41fc92e6e
parentcc659eb6a33016e412f89b797ea09b10fa4c5f3a (diff)
Reserve space for vector.
Varoius code cleanup for c++11.
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/documentprotocol.cpp12
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/documentprotocol.h2
-rw-r--r--messagebus/src/vespa/messagebus/messagebus.cpp19
-rw-r--r--messagebus/src/vespa/messagebus/messenger.cpp22
-rw-r--r--staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp2
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/storageprotocol.cpp2
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h4
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.cpp13
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.h2
-rw-r--r--vespalib/src/vespa/vespalib/data/slime/binary_format.cpp55
-rw-r--r--vespalib/src/vespa/vespalib/data/slime/symbol_table.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/data/slime/symbol_table.h6
12 files changed, 63 insertions, 86 deletions
diff --git a/documentapi/src/vespa/documentapi/messagebus/documentprotocol.cpp b/documentapi/src/vespa/documentapi/messagebus/documentprotocol.cpp
index a2e8219e916..01b8515400b 100644
--- a/documentapi/src/vespa/documentapi/messagebus/documentprotocol.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/documentprotocol.cpp
@@ -23,9 +23,9 @@ const mbus::string DocumentProtocol::NAME = "document";
DocumentProtocol::DocumentProtocol(const LoadTypeSet& loadTypes,
std::shared_ptr<const DocumentTypeRepo> repo,
const string &configId) :
- _routingPolicyRepository(new RoutingPolicyRepository()),
- _routableRepository(new RoutableRepository(loadTypes)),
- _repo(repo)
+ _routingPolicyRepository(std::make_unique<RoutingPolicyRepository>()),
+ _routableRepository(std::make_unique<RoutableRepository>(loadTypes)),
+ _repo(std::move(repo))
{
// Prepare config string for routing policy factories.
string cfg = (configId.empty() ? "client" : configId);
@@ -148,10 +148,8 @@ DocumentProtocol &
DocumentProtocol::putRoutableFactory(uint32_t type, IRoutableFactory::SP factory,
const std::vector<vespalib::VersionSpecification> &versions)
{
- for (std::vector<vespalib::VersionSpecification>::const_iterator it = versions.begin();
- it != versions.end(); ++it)
- {
- putRoutableFactory(type, factory, *it);
+ for (const auto & version : versions) {
+ putRoutableFactory(type, factory, version);
}
return *this;
}
diff --git a/documentapi/src/vespa/documentapi/messagebus/documentprotocol.h b/documentapi/src/vespa/documentapi/messagebus/documentprotocol.h
index 5582c0ea153..eeae4553b3b 100644
--- a/documentapi/src/vespa/documentapi/messagebus/documentprotocol.h
+++ b/documentapi/src/vespa/documentapi/messagebus/documentprotocol.h
@@ -197,7 +197,7 @@ public:
DocumentProtocol(const LoadTypeSet& loadTypes,
std::shared_ptr<const document::DocumentTypeRepo> repo,
const string &configId = "");
- ~DocumentProtocol();
+ ~DocumentProtocol() override;
/**
* Adds a new routable factory to this protocol. This method is thread-safe, and may be invoked on a
diff --git a/messagebus/src/vespa/messagebus/messagebus.cpp b/messagebus/src/vespa/messagebus/messagebus.cpp
index d277063a273..fee9504007b 100644
--- a/messagebus/src/vespa/messagebus/messagebus.cpp
+++ b/messagebus/src/vespa/messagebus/messagebus.cpp
@@ -99,7 +99,7 @@ MessageBus::MessageBus(INetwork &net, ProtocolSet protocols) :
MessageBusParams params;
while (!protocols.empty()) {
IProtocol::SP protocol = protocols.extract();
- if (protocol.get() != nullptr) {
+ if (protocol) {
params.addProtocol(protocol);
}
}
@@ -132,8 +132,7 @@ MessageBus::~MessageBus()
bool done = false;
while (!done) {
vespalib::Gate gate;
- Messenger::ITask::UP task(new ShutdownTask(_network, *_msn, done, gate));
- _msn->enqueue(std::move(task));
+ _msn->enqueue(std::make_unique<ShutdownTask>(_network, *_msn, done, gate));
gate.await();
}
}
@@ -157,11 +156,10 @@ MessageBus::setup(const MessageBusParams &params)
// Start messenger.
IRetryPolicy::SP retryPolicy = params.getRetryPolicy();
- if (retryPolicy.get() != nullptr) {
- _resender.reset(new Resender(retryPolicy));
+ if (retryPolicy) {
+ _resender = std::make_unique<Resender>(retryPolicy);
- Messenger::ITask::UP task(new ResenderTask(*_resender));
- _msn->addRecurrentTask(std::move(task));
+ _msn->addRecurrentTask(std::make_unique<ResenderTask>(*_resender));
}
if (!_msn->start()) {
throw vespalib::NetworkSetupFailureException("Failed to start messenger.");
@@ -273,7 +271,7 @@ MessageBus::sync()
void
MessageBus::handleMessage(Message::UP msg)
{
- if (_resender.get() != nullptr && msg->hasBucketSequence()) {
+ if (_resender && msg->hasBucketSequence()) {
deliverError(std::move(msg), ErrorCode::SEQUENCE_ERROR,
"Bucket sequences not supported when resender is enabled.");
return;
@@ -292,8 +290,7 @@ MessageBus::setupRouting(const RoutingSpec &spec)
LOG(info, "Protocol '%s' is not supported, ignoring routing table.", cfg.getProtocol().c_str());
continue;
}
- RoutingTable::SP rt(new RoutingTable(cfg));
- rtm[cfg.getProtocol()] = rt;
+ rtm[cfg.getProtocol()] = std::make_shared<RoutingTable>(cfg);
}
{
LockGuard guard(_lock);
@@ -383,7 +380,7 @@ MessageBus::deliverMessage(Message::UP msg, const string &session)
void
MessageBus::deliverError(Message::UP msg, uint32_t errCode, const string &errMsg)
{
- Reply::UP reply(new EmptyReply());
+ auto reply = std::make_unique<EmptyReply>();
reply->swapState(*msg);
reply->addError(Error(errCode, errMsg));
diff --git a/messagebus/src/vespa/messagebus/messenger.cpp b/messagebus/src/vespa/messagebus/messenger.cpp
index 63df7f2f482..5313c4adcbb 100644
--- a/messagebus/src/vespa/messagebus/messenger.cpp
+++ b/messagebus/src/vespa/messagebus/messenger.cpp
@@ -33,7 +33,7 @@ public:
}
~MessageTask() {
- if (_msg.get() != nullptr) {
+ if (_msg) {
_msg->discard();
}
}
@@ -43,7 +43,7 @@ public:
}
uint8_t priority() const override {
- if (_msg.get() != nullptr) {
+ if (_msg) {
return _msg->priority();
}
@@ -65,7 +65,7 @@ public:
}
~ReplyTask() {
- if (_reply.get() != nullptr) {
+ if (_reply) {
_reply->discard();
}
}
@@ -75,7 +75,7 @@ public:
}
uint8_t priority() const override {
- if (_reply.get() != nullptr) {
+ if (_reply) {
return _reply->priority();
}
@@ -206,7 +206,7 @@ Messenger::Run(FastOS_ThreadInterface *thread, void *arg)
_queue.pop();
}
}
- if (task.get() != nullptr) {
+ if (task) {
try {
task->run();
} catch (const std::exception &e) {
@@ -223,16 +223,14 @@ Messenger::Run(FastOS_ThreadInterface *thread, void *arg)
void
Messenger::addRecurrentTask(ITask::UP task)
{
- ITask::UP add(new AddRecurrentTask(_children, std::move(task)));
- enqueue(std::move(add));
+ enqueue(std::make_unique<AddRecurrentTask>(_children, std::move(task)));
}
void
Messenger::discardRecurrentTasks()
{
vespalib::Gate gate;
- ITask::UP task(new DiscardRecurrentTasks(gate, _children));
- enqueue(std::move(task));
+ enqueue(std::make_unique<DiscardRecurrentTasks>(gate, _children));
gate.await();
}
@@ -248,13 +246,13 @@ Messenger::start()
void
Messenger::deliverMessage(Message::UP msg, IMessageHandler &handler)
{
- enqueue(ITask::UP(new MessageTask(std::move(msg), handler)));
+ enqueue(std::make_unique<MessageTask>(std::move(msg), handler));
}
void
Messenger::deliverReply(Reply::UP reply, IReplyHandler &handler)
{
- enqueue(ITask::UP(new ReplyTask(std::move(reply), handler)));
+ enqueue(std::make_unique<ReplyTask>(std::move(reply), handler));
}
void
@@ -273,7 +271,7 @@ void
Messenger::sync()
{
vespalib::Gate gate;
- enqueue(ITask::UP(new SyncTask(gate)));
+ enqueue(std::make_unique<SyncTask>(gate));
gate.await();
}
diff --git a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
index 7d047e36566..6c71d0a2cf6 100644
--- a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
+++ b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
@@ -36,7 +36,7 @@ MemoryDataStoreTest::testMemoryDataStore()
void
MemoryDataStoreTest::testVariableSizeVector()
{
- VariableSizeVector v(256);
+ VariableSizeVector v(20000, 5*20000);
for (size_t i(0); i < 10000; i++) {
asciistream os;
os << i;
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.cpp b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.cpp
index 33fcc29db11..b5107e68454 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.cpp
@@ -25,7 +25,7 @@ StorageProtocol::StorageProtocol(const std::shared_ptr<const document::DocumentT
{
}
-StorageProtocol::~StorageProtocol() {}
+StorageProtocol::~StorageProtocol() = default;
mbus::IRoutingPolicy::UP
StorageProtocol::createPolicy(const mbus::string&, const mbus::string&) const
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h
index 67ea121c340..40f2d26d833 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h
+++ b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h
@@ -17,13 +17,13 @@ public:
StorageProtocol(const std::shared_ptr<const document::DocumentTypeRepo>,
const documentapi::LoadTypeSet& loadTypes);
- ~StorageProtocol();
+ ~StorageProtocol() override;
const mbus::string& getName() const override { return NAME; }
mbus::IRoutingPolicy::UP createPolicy(const mbus::string& name, const mbus::string& param) const override;
mbus::Blob encode(const vespalib::Version&, const mbus::Routable&) const override;
mbus::Routable::UP decode(const vespalib::Version&, mbus::BlobRef) const override;
- virtual bool requireSequencing() const override { return true; }
+ bool requireSequencing() const override { return true; }
private:
ProtocolSerialization5_0 _serializer5_0;
ProtocolSerialization5_1 _serializer5_1;
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
index 866fb7d4929..df1b68cff12 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
@@ -15,9 +15,7 @@ MemoryDataStore::MemoryDataStore(Alloc && initialAlloc, Lock * lock) :
_buffers.emplace_back(std::move(initialAlloc));
}
-MemoryDataStore::~MemoryDataStore()
-{
-}
+MemoryDataStore::~MemoryDataStore() = default;
MemoryDataStore::Reference
MemoryDataStore::push_back(const void * data, const size_t sz)
@@ -40,15 +38,14 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
return ref;
}
-VariableSizeVector::VariableSizeVector(size_t initialSize) :
+VariableSizeVector::VariableSizeVector(size_t initialCount, size_t initialBufferSize) :
_vector(),
- _store(Alloc::alloc(initialSize))
+ _store(Alloc::alloc(initialBufferSize))
{
+ _vector.reserve(initialCount);
}
-VariableSizeVector::~VariableSizeVector()
-{
-}
+VariableSizeVector::~VariableSizeVector() = default;
VariableSizeVector::Reference
VariableSizeVector::push_back(const void * data, const size_t sz)
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h
index 3ef0e3ee986..2d02bfb107c 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.h
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h
@@ -99,7 +99,7 @@ public:
};
VariableSizeVector(const VariableSizeVector &) = delete;
VariableSizeVector & operator = (const VariableSizeVector &) = delete;
- VariableSizeVector(size_t initialSize=256);
+ VariableSizeVector(size_t initialCount, size_t initialBufferSize);
~VariableSizeVector();
iterator begin() { return iterator(_vector, 0); }
iterator end() { return iterator(_vector, size()); }
diff --git a/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp b/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp
index 2febe3f4405..1956dde689c 100644
--- a/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp
+++ b/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp
@@ -7,10 +7,7 @@
#include <vespa/log/log.h>
LOG_SETUP(".vespalib.data.slime.binary_format");
-namespace vespalib {
-namespace slime {
-
-namespace binary_format {
+namespace vespalib::slime::binary_format {
struct BinaryEncoder : public ArrayTraverser,
public ObjectSymbolTraverser
@@ -242,32 +239,6 @@ size_t decode(const Memory &memory, Slime &slime, const Inserter &inserter) {
return input.failed() ? 0 : input.get_offset();
}
-} // namespace vespalib::slime::binary_format
-
-void
-BinaryFormat::encode(const Slime &slime, Output &output)
-{
- size_t chunk_size = 8000;
- OutputWriter out(output, chunk_size);
- binary_format::BinaryEncoder encoder(out);
- encoder.encodeSymbolTable(slime);
- encoder.encodeValue(slime.get());
-}
-
-size_t
-BinaryFormat::decode(const Memory &memory, Slime &slime)
-{
- return binary_format::decode<false>(memory, slime, SlimeInserter(slime));
-}
-
-size_t
-BinaryFormat::decode_into(const Memory &memory, Slime &slime, const Inserter &inserter)
-{
- return binary_format::decode<true>(memory, slime, inserter);
-}
-
-namespace binary_format {
-
void
write_cmpr_ulong(OutputWriter &out, uint64_t value) {
out.commit(encode_cmpr_ulong(out.reserve(10), value));
@@ -288,5 +259,25 @@ write_type_and_size(OutputWriter &out, uint32_t type, uint64_t size) {
}
-} // namespace vespalib::slime
-} // namespace vespalib
+namespace vespalib::slime {
+
+void
+BinaryFormat::encode(const Slime &slime, Output &output) {
+ size_t chunk_size = 8000;
+ OutputWriter out(output, chunk_size);
+ binary_format::BinaryEncoder encoder(out);
+ encoder.encodeSymbolTable(slime);
+ encoder.encodeValue(slime.get());
+}
+
+size_t
+BinaryFormat::decode(const Memory &memory, Slime &slime) {
+ return binary_format::decode<false>(memory, slime, SlimeInserter(slime));
+}
+
+size_t
+BinaryFormat::decode_into(const Memory &memory, Slime &slime, const Inserter &inserter) {
+ return binary_format::decode<true>(memory, slime, inserter);
+}
+
+}
diff --git a/vespalib/src/vespa/vespalib/data/slime/symbol_table.cpp b/vespalib/src/vespa/vespalib/data/slime/symbol_table.cpp
index 643e23b5887..a7de28932f3 100644
--- a/vespalib/src/vespa/vespalib/data/slime/symbol_table.cpp
+++ b/vespalib/src/vespa/vespalib/data/slime/symbol_table.cpp
@@ -3,15 +3,14 @@
#include "symbol_table.h"
#include <vespa/vespalib/stllike/hash_map.hpp>
-namespace vespalib {
-namespace slime {
+namespace vespalib::slime {
SymbolTable::SymbolTable(size_t expectedNumSymbols) :
_symbols(3*expectedNumSymbols),
- _names()
+ _names(expectedNumSymbols, expectedNumSymbols*16)
{ }
-SymbolTable::~SymbolTable() { }
+SymbolTable::~SymbolTable() = default;
void
SymbolTable::clear() {
@@ -39,5 +38,4 @@ SymbolTable::lookup(const Memory &name) const {
return pos->second;
}
-} // namespace vespalib::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 c726da0319b..30599d76597 100644
--- a/vespalib/src/vespa/vespalib/data/slime/symbol_table.h
+++ b/vespalib/src/vespa/vespalib/data/slime/symbol_table.h
@@ -7,8 +7,7 @@
#include <vespa/vespalib/stllike/hash_map.h>
#include <vespa/vespalib/data/memorydatastore.h>
-namespace vespalib {
-namespace slime {
+namespace vespalib::slime {
/**
* Maps between strings and symbols.
@@ -43,6 +42,5 @@ public:
void clear();
};
-} // namespace vespalib::slime
-} // namespace vespalib
+}