From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS2116 193.90.0.0/16 X-Spam-Status: No, score=-2.2 required=3.0 tests=AWL,BAYES_00, RCVD_IN_BRBL_LASTEXT,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL, RDNS_NONE,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (unknown [193.90.12.88]) by dcvr.yhbt.net (Postfix) with ESMTP id DB3AF20323 for ; Fri, 17 Mar 2017 01:57:37 +0000 (UTC) From: Eric Wong To: raindrops-public@bogomips.org Subject: [PATCH] avoid reading errno repeatedly Date: Fri, 17 Mar 2017 01:57:34 +0000 Message-Id: <20170317015734.9783-1-e@80x24.org> List-Id: errno is in the thread-specific section and it is slightly cheaper to read it once rather than twice. Recent versions of mainline Ruby itself follows the same pattern. --- ext/raindrops/raindrops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/raindrops/raindrops.c b/ext/raindrops/raindrops.c index 390b8b8..9090839 100644 --- a/ext/raindrops/raindrops.c +++ b/ext/raindrops/raindrops.c @@ -117,7 +117,9 @@ retry: r->drops = mmap(NULL, tmp, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if (r->drops == MAP_FAILED) { - if ((errno == EAGAIN || errno == ENOMEM) && tries-- > 0) { + int err = errno; + + if ((err == EAGAIN || err == ENOMEM) && tries-- > 0) { rb_gc(); goto retry; } @@ -153,7 +155,9 @@ static void resize(struct raindrops *r, size_t new_rd_size) rv = mremap(old_address, old_size, new_size, MREMAP_MAYMOVE); if (rv == MAP_FAILED) { - if (errno == EAGAIN || errno == ENOMEM) { + int err = errno; + + if (err == EAGAIN || err == ENOMEM) { rb_gc(); rv = mremap(old_address, old_size, new_size, 0); } -- EW