MCPcopy Create free account
hub / github.com/couchbase/fleece / diff_halfMatchI

Method diff_halfMatchI

Fleece/Support/diff_match_patch.hh:852–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

850 */
851 private:
852 static bool diff_halfMatchI(const string_t &longtext, const string_t &shorttext, ssize_t i, HalfMatchResult& best) {
853 // Start with a 1/4 length substring at position i as a seed.
854 const string_t seed = safeMid(longtext, i, longtext.length() / 4);
855 size_t j = string_t::npos;
856 while ((j = shorttext.find(seed, j + 1)) != string_t::npos) {
857 const ssize_t prefixLength = diff_commonPrefix(safeMid(longtext, i),
858 safeMid(shorttext, j));
859 const ssize_t suffixLength = diff_commonSuffix(longtext.substr(0, i),
860 shorttext.substr(0, j));
861 if ((ssize_t)best.mid_common.length() < suffixLength + prefixLength) {
862 best.mid_common = safeMid(shorttext, j - suffixLength, suffixLength)
863 + safeMid(shorttext, j, prefixLength);
864 best.text1_a = longtext.substr(0, i - suffixLength);
865 best.text1_b = safeMid(longtext, i + prefixLength);
866 best.text2_a = shorttext.substr(0, j - suffixLength);
867 best.text2_b = safeMid(shorttext, j + prefixLength);
868 }
869 }
870 return best.mid_common.length() * 2 >= longtext.length();
871 }
872
873 /**
874 * Reduce the number of edits by eliminating semantically trivial equalities.

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected