diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-07 12:50:07 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-07 12:50:07 +0200 |
commit | c00d5fb305abff370f869dec0e9404f8a4a5646b (patch) | |
tree | 12794ff568d272e7326f6502727443e7928cd64c /common/entitybuffer.cpp | |
parent | b7873e621ef45badaa70e2d285998c486920df4a (diff) | |
download | sink-c00d5fb305abff370f869dec0e9404f8a4a5646b.tar.gz sink-c00d5fb305abff370f869dec0e9404f8a4a5646b.zip |
Use memcpy to copy tables into vectors.
Ideally we wouldn't be copying at all, and somehow cast the table to a vector.
Unfortunately I haven't figured out how to do that, and this solution at least
gets us from 0.065 ms to 0.028 ms in testCreateCommand.
Diffstat (limited to 'common/entitybuffer.cpp')
-rw-r--r-- | common/entitybuffer.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/common/entitybuffer.cpp b/common/entitybuffer.cpp index 5ba4afe..b555ac3 100644 --- a/common/entitybuffer.cpp +++ b/common/entitybuffer.cpp | |||
@@ -56,17 +56,24 @@ void EntityBuffer::extractResourceBuffer(void *dataValue, int dataSize, const st | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize) | 59 | flatbuffers::Offset<flatbuffers::Vector<uint8_t> > EntityBuffer::appendAsVector(flatbuffers::FlatBufferBuilder &fbb, void const *data, size_t size) |
60 | { | 60 | { |
61 | auto metadata = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(metadataData), metadataSize); | 61 | //Since we do memcpy trickery, this will only work on little endian |
62 | auto resource = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(resourceData), resourceSize); | 62 | assert(FLATBUFFERS_LITTLEENDIAN); |
63 | auto local = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(localData), localSize); | 63 | auto metadata = fbb.CreateUninitializedVector<uint8_t>(size); |
64 | auto builder = Akonadi2::EntityBuilder(fbb); | 64 | { |
65 | builder.add_metadata(metadata); | 65 | auto ptr = reinterpret_cast<flatbuffers::Vector<uint8_t> *>(fbb.GetBufferPointer())->Data(); |
66 | builder.add_resource(resource); | 66 | std::memcpy((void*)ptr, data, size); |
67 | builder.add_local(local); | 67 | } |
68 | return metadata; | ||
69 | } | ||
68 | 70 | ||
69 | auto buffer = builder.Finish(); | 71 | void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize) |
70 | Akonadi2::FinishEntityBuffer(fbb, buffer); | 72 | { |
73 | auto metadata = appendAsVector(fbb, metadataData, metadataSize); | ||
74 | auto resource = appendAsVector(fbb, resourceData, resourceSize); | ||
75 | auto local = appendAsVector(fbb, localData, localSize); | ||
76 | auto entity = Akonadi2::CreateEntity(fbb, metadata, resource, local); | ||
77 | Akonadi2::FinishEntityBuffer(fbb, entity); | ||
71 | } | 78 | } |
72 | 79 | ||