Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/google/vcencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class CodeTableWriterInterface;
class HashedDictionary {
public:
HashedDictionary(const char* dictionary_contents,
size_t dictionary_size);
size_t dictionary_size,
bool copy = true);
~HashedDictionary();

// Init() must be called before using the HashedDictionary as an argument
Expand Down
9 changes: 5 additions & 4 deletions src/vcdiffengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@

namespace open_vcdiff {

VCDiffEngine::VCDiffEngine(const char* dictionary, size_t dictionary_size)
VCDiffEngine::VCDiffEngine(const char* dictionary, size_t dictionary_size, bool copy)
// If dictionary_size == 0, then dictionary could be NULL. Guard against
// using a NULL value.
: dictionary_((dictionary_size > 0) ? new char[dictionary_size] : ""),
: dictionary_((dictionary_size > 0) ? (copy ? new char[dictionary_size] : dictionary) : ""),
owns_dictionary_(copy),
dictionary_size_(dictionary_size),
hashed_dictionary_(NULL) {
if (dictionary_size > 0) {
if (dictionary_size > 0 && copy) {
memcpy(const_cast<char*>(dictionary_), dictionary, dictionary_size);
}
}

VCDiffEngine::~VCDiffEngine() {
delete hashed_dictionary_;
if (dictionary_size_ > 0) {
if (dictionary_size_ > 0 && owns_dictionary_) {
delete[] dictionary_;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/vcdiffengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class VCDiffEngine {
// aligned on block boundaries in the dictionary text.
static const size_t kMinimumMatchSize = 32;

VCDiffEngine(const char* dictionary, size_t dictionary_size);
VCDiffEngine(const char* dictionary, size_t dictionary_size, bool copy = true);

~VCDiffEngine();

Expand Down Expand Up @@ -107,6 +107,8 @@ class VCDiffEngine {

const char* dictionary_; // A copy of the dictionary contents

bool owns_dictionary_;

const size_t dictionary_size_;

// A hash that contains one element for every kBlockSize bytes of dictionary_.
Expand Down
5 changes: 3 additions & 2 deletions src/vcencoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ CodeTableWriterInterface* create_writer(
} // namespace

HashedDictionary::HashedDictionary(const char* dictionary_contents,
size_t dictionary_size)
: engine_(new VCDiffEngine(dictionary_contents, dictionary_size)) { }
size_t dictionary_size,
bool copy)
: engine_(new VCDiffEngine(dictionary_contents, dictionary_size, copy)) { }

HashedDictionary::~HashedDictionary() { delete engine_; }

Expand Down