kasei / perl-iri

Perl implementation of Internationalized Resource Identifiers (IRIs)
0 stars 6 forks source link

Optimize coercions #14

Open kjetilk opened 5 years ago

kjetilk commented 5 years ago

As a follow-up to #13 , I'm thinking that it should be possible to have coercions that do not need to go through the full parsing step unless it actually originates from Str. So, rather than parse, perhaps it could be done by running through the components of the IRI?

kasei commented 5 years ago

Definitely worth looking into. I wonder if lots of extraction from an existing URI object might actually be more expensive than a single regex match in the IRI code.

kjetilk commented 4 years ago

I tried to explore this by constructing an IRI object with

my $iri = IRI->new(lazy => 1,
         'components' => {
                'scheme' => 'http',
                'path' => '/',
                'host' => 'example.com'
              },
             );

but that doesn't seem to work, even though it seems to have the right value in the constructor. It seems URI objects can be constructed this way.

If we were to do this, that would be the route to go, wouldn't it?

kasei commented 4 years ago

I'd be happy to have this functionality, but it might require some changes. It's been a long time since I looked at that code, but I think the components are all generated by the parsing step, so there would need to be changes to allow constructing in the other directions (supply components, generate the full string).