std.net.curl : Performance

Daniel Kozak kozzi11 at gmail.com
Mon Nov 9 20:57:33 UTC 2020


On Mon, Nov 9, 2020 at 9:50 PM rinfz via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:

> 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 = [];
> }
>

In fact he does not need foreach. Because he use it on empty result
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20201109/1bfc247e/attachment.htm>


More information about the Digitalmars-d-learn mailing list