From e46a5697e5ac03586036225c38d0d87e30d1fe43 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 9 Feb 2018 21:47:18 +1100 Subject: [PATCH] Add a limit to the size of selection with which we will try to diff on pipe Limit to 100K of data for now, as we diff at the byte level. --- src/normal.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/normal.cc b/src/normal.cc index 86c49e00..1019ef46 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -470,6 +470,16 @@ void command(Context& context, NormalParams params) void apply_diff(Buffer& buffer, BufferCoord pos, StringView before, StringView after) { + // The diff algorithm is O(ND) with N the sum of string len, and D the diff count + // do not use it if our data is too big + constexpr ByteCount size_limit = 100 * 1024; + if (before.length() + after.length() > size_limit) + { + buffer.erase(pos, buffer.advance(pos, before.length())); + buffer.insert(pos, after); + return; + } + auto diffs = find_diff(before.begin(), (int)before.length(), after.begin(), (int)after.length()); for (auto& diff : diffs)