From 6e3c0f74246d09d35e80d748abf36f7f399eb73f Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Sat, 24 May 2025 13:16:24 -0400 Subject: [PATCH 1/2] removes tool-versions to be agnostic, removes diffy dependency --- .tool-versions | 2 -- lib/delta.ex | 13 ++++++++++++- mix.exs | 1 - 3 files changed, 12 insertions(+), 4 deletions(-) delete mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 7fe5a86..0000000 --- a/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -elixir 1.13.4-otp-24 -erlang 24.3.4.2 diff --git a/lib/delta.ex b/lib/delta.ex index d005171..ab16121 100644 --- a/lib/delta.ex +++ b/lib/delta.ex @@ -519,6 +519,10 @@ defmodule Delta do iex> Delta.compose(a, diff) == b true """ + + @check_lines Application.compile_env(:delta, :diff_fast, false) + @timeout Application.compile_env(:delta, :diff_timeout, nil) + @doc since: "0.4.0" @spec diff(t, t) :: t def diff(base, other) @@ -531,12 +535,19 @@ defmodule Delta do diff = base_string - |> :diffy.diff(other_string) + |> Dmp.Diff.compute(other_string, @check_lines, deadline()) |> Dmp.Diff.cleanup_semantic() do_diff(base, other, diff, [], nil, 0) end + @compile {:inline, deadline: 0} + if @timeout do + defp deadline, do: :os.system_time(:millsecond) + round(@timeout * 1000) + else + defp deadline, do: :never + end + defp diffable_string(delta) do delta |> Enum.map(fn diff --git a/mix.exs b/mix.exs index bdee264..27ea4e2 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,6 @@ defmodule Delta.MixProject do defp deps do [ {:diff_match_patch, "~> 0.2"}, - {:diffy, "~> 1.1"}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} ] end From e0936cf9cdbf798a40d4b9c3fbccfff2b2076505 Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Sat, 24 May 2025 13:23:31 -0400 Subject: [PATCH 2/2] documentation on library options --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 0f7d16a..97ee559 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,20 @@ base |> Delta.compose(change) |> Delta.compose(inverted) == base
+## Global Library options + +In your application, these are settable in `config.exs` by doing: + +`config :delta, :