X Tutup
The Wayback Machine - https://web.archive.org/web/20200920090518/https://github.com/google/diff-match-patch/issues/85
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old + delta => new #85

Open
josephernest opened this issue Feb 18, 2020 · 0 comments
Open

old + delta => new #85

josephernest opened this issue Feb 18, 2020 · 0 comments

Comments

@josephernest
Copy link

@josephernest josephernest commented Feb 18, 2020

import diff_match_patch as dmp_module

old = "hello how are you? very good and you? blablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla. thanks for asking! this text will be removed."
delta = "+will be removed.\t=138\t+new text here.\t=19\t-27"

dmp = dmp_module.diff_match_patch()
new = dmp.patch_apply(dmp.patch_make(old, dmp.diff_fromDelta(old, delta)), old)[0]
print(new)

Isn't there a simpler way to apply a delta to an input string, rather than doing the complex :

  • delta -> diff with diff_fromDelta (uses old once)
  • diff -> patch with patch_make (uses old again)
  • patch -> output string with patch_apply (uses old a third time!)

i.e.

dmp.patch_apply(dmp.patch_make(old, dmp.diff_fromDelta(old, delta)), old)

This seems to be optimal in terms of byte size (if the two strings are 200 KB and changes are only 20 bytes, delta will be only < 50 bytes, which is good for transfer over network)...

... but probably not in terms of CPU: if old is a big string, it will be processed three times by the previous functions!

Isn't there a better way to apply a delta to a string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup