std.net.curl : Performance

rinfz cherez at mailbox.org
Mon Nov 9 20:45:41 UTC 2020


On Monday, 9 November 2020 at 20:40:59 UTC, rinfz wrote:
> On Monday, 9 November 2020 at 19:55:07 UTC, Vino wrote:
>> ...
>
> The only curl option you need to set within the loop is the 
> CurlOption.url. So your foreach block should look more like:
>
> foreach (...) {
>     string url = chain(apihost, only(':'), to!string(apiport), 
> apiuri).to!string;
>     https.handle.set(CurlOption.url, url);
>     https.perform();
>     scope(failure) exit(-4);
>     scope(exit) https.shutdown;
>     apidata.insert(tuple(seq, cast(string) content));
>     content = [];
> }
>
> Every other line can be placed before the foreach.

In fact, you don't need url in there either since it's not 
dependent on loop variables, and you don't need the scope guards 
if this is running in main (you can move them out of the loop 
too).

foreach (...) {
     https.handle.set(CurlOption.url, url);
     https.perform();
     apidata.insert(tuple(seq, cast(string) content));
     content = [];
}


More information about the Digitalmars-d-learn mailing list