This repository was archived by the owner on Apr 18, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ class CodeTableWriterInterface;
3838class 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
Original file line number Diff line number Diff line change 2323
2424namespace 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
3738VCDiffEngine::~VCDiffEngine () {
3839 delete hashed_dictionary_;
39- if (dictionary_size_ > 0 ) {
40+ if (dictionary_size_ > 0 && owns_dictionary_ ) {
4041 delete[] dictionary_;
4142 }
4243}
Original file line number Diff line number Diff 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_.
Original file line number Diff line number Diff line change @@ -57,8 +57,9 @@ CodeTableWriterInterface* create_writer(
5757} // namespace
5858
5959HashedDictionary::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
6364HashedDictionary::~HashedDictionary () { delete engine_; }
6465
You can’t perform that action at this time.
0 commit comments