From c2e6ffdebba902a59f51d9c5e20416adabf4c178 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sat, 30 Mar 2019 22:11:04 +0100 Subject: [PATCH] Optimize RDF.PrefixMap.new/1 creation from another PrefixMap --- lib/rdf/prefix_map.ex | 2 ++ test/unit/prefix_map_test.exs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/rdf/prefix_map.ex b/lib/rdf/prefix_map.ex index 68981b6..d596285 100644 --- a/lib/rdf/prefix_map.ex +++ b/lib/rdf/prefix_map.ex @@ -23,6 +23,8 @@ defmodule RDF.PrefixMap do """ def new(map) + def new(%__MODULE__{} = prefix_map), do: prefix_map + def new(map) when is_map(map) do %__MODULE__{map: Map.new(map, &normalize/1)} end diff --git a/test/unit/prefix_map_test.exs b/test/unit/prefix_map_test.exs index 595dc80..9c8d7bd 100644 --- a/test/unit/prefix_map_test.exs +++ b/test/unit/prefix_map_test.exs @@ -45,6 +45,10 @@ defmodule RDF.PrefixMapTest do ) == @example2 end + test "with another prefix map" do + assert PrefixMap.new(@example2) == @example2 + end + test "when the IRI namespace is given as a RDF.Vocabulary.Namespace" do assert PrefixMap.new( ex1: "http://example.com/foo/",