44from  urllib .parse  import  unquote , urldefrag , urljoin 
55
66from  attrs  import  evolve , field 
7- from  pyrsistent  import  m , plist , s 
7+ from  pyrsistent  import  m , plist , pmap ,  s 
88from  pyrsistent .typing  import  PList , PMap , PSet 
99
1010from  referencing ._attrs  import  define , frozen 
@@ -178,16 +178,6 @@ def with_identified_resources(
178178            uncrawled = uncrawled .persistent (),
179179        )
180180
181-     def  _with_anchors (
182-         self ,
183-         uri : str ,
184-         anchors : Iterable [AnchorType ],
185-     ) ->  Registry :
186-         assert  uri .endswith ("#" ) or  "#"  not  in   uri , uri 
187-         resource , old  =  self ._contents [uri ]
188-         new  =  old .update ({anchor .name : anchor  for  anchor  in  anchors })
189-         return  evolve (self , contents = self ._contents .set (uri , (resource , new )))
190- 
191181    def  resource_at (
192182        self ,
193183        uri : str ,
@@ -199,26 +189,25 @@ def resource_at(
199189        return  * at_uri , self 
200190
201191    def  _crawl (self ) ->  Registry :
202-         registry  =  self 
203-         resources  =  [(uri , self . _contents [uri ][0 ]) for  uri  in  self ._uncrawled ]
192+         contents  =  self . _contents . evolver () 
193+         resources  =  [(uri , contents [uri ][0 ]) for  uri  in  self ._uncrawled ]
204194        while  resources :
205195            base_uri , resource  =  resources .pop ()
196+             anchors  =  pmap ((each .name , each ) for  each  in  resource .anchors ())
197+ 
206198            id  =  resource .id ()
207199            if  id  is  None :
208200                uri  =  base_uri 
201+ 
202+                 if  anchors :
203+                     old , old_anchors  =  contents [uri ]
204+                     contents [uri ] =  old , old_anchors .update (anchors )
209205            else :
210206                uri  =  urljoin (base_uri , id )
211-                 registry  =  registry .with_identified_resource (
212-                     uri = uri ,
213-                     resource = resource ,
214-                 )
215- 
216-             anchors  =  resource .anchors ()
217-             if  anchors :
218-                 registry  =  registry ._with_anchors (uri , anchors )
207+                 contents [uri ] =  resource , anchors 
219208
220209            resources .extend ((uri , each ) for  each  in  resource .subresources ())
221-         return  evolve (registry , uncrawled = s ())
210+         return  evolve (self ,  contents = contents . persistent () , uncrawled = s ())
222211
223212    def  resolver (self , root : Schema , specification : Specification ) ->  Resolver :
224213        uri  =  specification .id_of (root ) or  "" 
0 commit comments