Skip to content

Commit

Permalink
Use StackBuffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Jun 25, 2015
1 parent 8372ad3 commit 8c4bbf4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/FileMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/mman.h>
#include <rct/Serializer.h>
#include <rct/Rct.h>
#include <rct/StackBuffer.h>
#include "Location.h"
#include <functional>

Expand Down Expand Up @@ -221,7 +222,7 @@ class FileMap
keySize = std::max<size_t>(str.size(), keySize);
}
memcpy(out.data() + sizeof(size_t), &keySize, sizeof(keySize));
char buf[keySize];
StackBuffer<1024> buf(keySize);
size_t entrySize = keySize;
if (const size_t size = FixedSize<Value>::value) {
entrySize += size;
Expand All @@ -232,7 +233,7 @@ class FileMap
out.reserve(valuesOffset);
idx = 0;
for (const auto &pair : map) {
memset(buf, 0, sizeof(buf));
memset(buf, 0, keySize);
const String &str = keys[idx++];
memcpy(buf, str.data(), str.size()); // no need to copy the \0 :-)
encodePair(buf, keySize, pair.second);
Expand Down
2 changes: 1 addition & 1 deletion src/rdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ int main(int argc, char** argv)
Path rcfile = Path::home() + ".rdmrc";
opterr = 0;

char *originalArgv[argc];
StackBuffer<128, char*> originalArgv(argc);
memcpy(originalArgv, argv, sizeof(originalArgv));
/* getopt will molest argv by moving pointers around when it sees
* fit. Their idea of an optional argument is different from ours so we
Expand Down

0 comments on commit 8c4bbf4

Please sign in to comment.