Improve performance of RDF.PrefixMap.prefixed_name_to_iri/2
This commit is contained in:
parent
15002a0bbb
commit
c17cf8297c
1 changed files with 9 additions and 6 deletions
|
@ -396,12 +396,15 @@ defmodule RDF.PrefixMap do
|
||||||
@spec prefixed_name_to_iri(t, String.t()) :: IRI.t() | nil
|
@spec prefixed_name_to_iri(t, String.t()) :: IRI.t() | nil
|
||||||
def prefixed_name_to_iri(%__MODULE__{} = prefix_map, prefixed_name)
|
def prefixed_name_to_iri(%__MODULE__{} = prefix_map, prefixed_name)
|
||||||
when is_binary(prefixed_name) do
|
when is_binary(prefixed_name) do
|
||||||
Enum.find_value(prefix_map, fn {prefix, namespace} ->
|
case String.split(prefixed_name, ":", parts: 2) do
|
||||||
case String.replace_leading(prefixed_name, "#{prefix}:", IRI.to_string(namespace)) do
|
[prefix, name] ->
|
||||||
^prefixed_name -> nil
|
if ns = namespace(prefix_map, prefix) do
|
||||||
iri -> IRI.new(iri)
|
RDF.iri(ns.value <> name)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defimpl Enumerable do
|
defimpl Enumerable do
|
||||||
|
|
Loading…
Reference in a new issue