Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .tool-versions

This file was deleted.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ base |> Delta.compose(change) |> Delta.compose(inverted) == base

<br>

## Global Library options

In your application, these are settable in `config.exs` by doing:

`config :delta, :<option>, <value>`

### Compile-time
`timeout`: timeout (in seconds) for the diffing operation to complete. If you don't set this, there is no timeout.
`diff_fast`: (boolean) if true, performs a diff that is faster but is a less optimal diff

### Runtime

`custom_embeds`: ... insert description here ...

## Contributing

- [Fork][github-fork], Enhance, Send PR
Expand Down
13 changes: 12 additions & 1 deletion lib/delta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down