Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Commit bf89e98

Browse files
committed
Allow not copying the dictionary
1 parent 868f459 commit bf89e98

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/google/vcencoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class CodeTableWriterInterface;
3838
class HashedDictionary {
3939
public:
4040
HashedDictionary(const char* dictionary_contents,
41-
size_t dictionary_size);
41+
size_t dictionary_size,
42+
bool copy = true);
4243
~HashedDictionary();
4344

4445
// Init() must be called before using the HashedDictionary as an argument

src/vcdiffengine.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@
2323

2424
namespace open_vcdiff {
2525

26-
VCDiffEngine::VCDiffEngine(const char* dictionary, size_t dictionary_size)
26+
VCDiffEngine::VCDiffEngine(const char* dictionary, size_t dictionary_size, bool copy)
2727
// If dictionary_size == 0, then dictionary could be NULL. Guard against
2828
// using a NULL value.
29-
: dictionary_((dictionary_size > 0) ? new char[dictionary_size] : ""),
29+
: dictionary_((dictionary_size > 0) ? (copy ? new char[dictionary_size] : dictionary) : ""),
30+
owns_dictionary_(copy),
3031
dictionary_size_(dictionary_size),
3132
hashed_dictionary_(NULL) {
32-
if (dictionary_size > 0) {
33+
if (dictionary_size > 0 && copy) {
3334
memcpy(const_cast<char*>(dictionary_), dictionary, dictionary_size);
3435
}
3536
}
3637

3738
VCDiffEngine::~VCDiffEngine() {
3839
delete hashed_dictionary_;
39-
if (dictionary_size_ > 0) {
40+
if (dictionary_size_ > 0 && owns_dictionary_) {
4041
delete[] dictionary_;
4142
}
4243
}

src/vcdiffengine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class VCDiffEngine {
3737
// aligned on block boundaries in the dictionary text.
3838
static const size_t kMinimumMatchSize = 32;
3939

40-
VCDiffEngine(const char* dictionary, size_t dictionary_size);
40+
VCDiffEngine(const char* dictionary, size_t dictionary_size, bool copy = true);
4141

4242
~VCDiffEngine();
4343

@@ -107,6 +107,8 @@ class VCDiffEngine {
107107

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

110+
bool owns_dictionary_;
111+
110112
const size_t dictionary_size_;
111113

112114
// A hash that contains one element for every kBlockSize bytes of dictionary_.

src/vcencoder.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ CodeTableWriterInterface* create_writer(
5757
} // namespace
5858

5959
HashedDictionary::HashedDictionary(const char* dictionary_contents,
60-
size_t dictionary_size)
61-
: engine_(new VCDiffEngine(dictionary_contents, dictionary_size)) { }
60+
size_t dictionary_size,
61+
bool copy)
62+
: engine_(new VCDiffEngine(dictionary_contents, dictionary_size, copy)) { }
6263

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

0 commit comments

Comments
 (0)