1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "string_pool.h" #include <stdlib.h> StringPool::StringPool() { } StringPool::~StringPool() { for (char* b : pool_) { free(b); } } StringPiece StringPool::Add(StringPiece s) { char* b = static_cast<char*>(malloc(s.size())); memcpy(b, s.data(), s.size()); pool_.push_back(b); return StringPiece(b, s.size()); }