From patchwork Sun Jan 5 05:57:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 104084 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22D6B3858C51 for ; Sun, 5 Jan 2025 06:38:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22D6B3858C51 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256 header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=XOUPUy/e X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id 4371F385843F for ; Sun, 5 Jan 2025 06:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4371F385843F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4371F385843F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.179.128.66 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056831; cv=none; b=kMWQ4jnq4h2WptbFTJWWHXtaZHBKKxzCw5nOs9BsFwL2JOeT77P4Q0T+xmGctYLpKAwZCc8JdAhKIur6l8RQv3FLKLkMAD3nxuyE1ElEYcNsVo0obRHw+KjM5WLhERrL1E84+PKky5fLVL0cdug5b8zIlv0OegD+ePsmJ/UG+Fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056831; c=relaxed/simple; bh=ade+6IH6jO53kD4e8qfX/mMbtuwIc2vVsd37ceGzS2s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dDdL+FpQtSy7xhIRAPCZg2+aIQP9arcVTtBM0EyTfm8ehL3BKXXQKt0a4Ya5djzJjIOSDtCBjpLJUOrmz+Oand2go0MzItzCaqzch+WlqhL4A1hpVuqvU2XXYqp37EGgUPfKSaDfe8w5sF6jvZr5/XIRBzCJ6OzYPIMwW6gWj50= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4371F385843F Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id BCD5F3C123844 for ; Sat, 4 Jan 2025 22:00:30 -0800 (PST) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id fMlKkenh6_BT; Sat, 4 Jan 2025 22:00:30 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 5504E3C082EB9; Sat, 4 Jan 2025 22:00:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 5504E3C082EB9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1736056830; bh=Ke8JNgUqbH+Fndz5dulTxrWCu4bHenZ/TL2rWJ2DdHw=; h=From:To:Date:Message-ID:MIME-Version; b=XOUPUy/e527oavQVjUIy9WlYMrFBeVnGCVBVxgjz2QLGpCs8+An5akz227BVFRJLD 2OoaDc2vU5Fn5IBX57XTJyW9cp5yz6HoGdtfyRDvthx7EO1sKhoEQk1U/XbqxzwJUS SVssvXEe7PHCx3GB4P6weGDodHaCXxO1PtkaKcy4XxDZXAWlrrGSYbagEMEy1jndCI 7DcKdDvX5tN2yEv7VBXSWpG781LKEQpbXGCFteys1C/ZB8rLJ/AOvMb8p7ce/PkNNn RM2h2zu0kg4enh8e7hhn61R3pGDoRuv2utU2k//nEfd1eeanGiWwCcXRqfvS+o0BQr t4zbwAeUC4mog== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id d-8eZyDDt3SY; Sat, 4 Jan 2025 22:00:30 -0800 (PST) Received: from wing.home (unknown [47.154.28.214]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id 3EEC03C082EB5; Sat, 4 Jan 2025 22:00:30 -0800 (PST) From: Paul Eggert To: libc-alpha@sourceware.org Cc: Paul Eggert Subject: [PATCH 52/59] =?utf-8?b?UmVmYWN0b3IgbG9jYWx0aW1lIOKAmGlm4oCZIGlu?= =?utf-8?b?IF9fdHpmaWxlX2NvbXB1dGU=?= Date: Sat, 4 Jan 2025 21:57:27 -0800 Message-ID: <20250105055750.1668721-53-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.45.2 In-Reply-To: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> References: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org * time/tzfile.c (__tzfile_compute): Negate the sense of another ‘if’ to simplify future changes. Almost all of this is indenting changes. --- time/tzfile.c | 158 +++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/time/tzfile.c b/time/tzfile.c index 37b194df16..783518cd6d 100644 --- a/time/tzfile.c +++ b/time/tzfile.c @@ -601,100 +601,100 @@ __tzfile_compute (__time64_t timer, int use_localtime, *leap_correct = corr; *leap_hit = hit; - if (use_localtime) - { - unsigned char ti; + if (!use_localtime) + return; + + unsigned char ti; - if (__glibc_unlikely (timecnt == 0 ? tzspec == NULL - : timer < transitions[0])) + if (__glibc_unlikely (timecnt == 0 ? tzspec == NULL + : timer < transitions[0])) + { + /* TIMER is before the first transition; or there are no + transitions and no TZ string. Use the first type. */ + ti = 0; + } + else if (timecnt == 0 || timer >= transitions[timecnt - 1]) + { + /* TIMER is after the last transition. Use the TZ string if + it is present and we can convert to the broken down structure. */ + if (__glibc_likely (tzspec != NULL) + && __glibc_likely (__offtime (timer, 0, 0, tp) != NULL)) { - /* TIMER is before the first transition; or there are no - transitions and no TZ string. Use the first type. */ - ti = 0; + /* Use the rules from the TZ string to compute the change. */ + __tz_compute (timer, tp); + return; } - else if (timecnt == 0 || timer >= transitions[timecnt - 1]) - { - /* TIMER is after the last transition. Use the TZ string if - it is present and we can convert to the broken down structure. */ - if (__glibc_likely (tzspec != NULL) - && __glibc_likely (__offtime (timer, 0, 0, tp) != NULL)) - { - /* Use the rules from the TZ string to compute the change. */ - __tz_compute (timer, tp); - return; - } - i = timecnt; - goto found; - } - else + i = timecnt; + goto found; + } + else + { + /* Find the first transition after TIMER, and + then pick the type of the transition before it. */ + tzidx lo = 0; + tzidx hi = timecnt - 1; + /* Assume that DST is changing twice a year and guess + initial search spot from it. Half of a gregorian year + has on average 365.2425 * 86400 / 2 = 15778476 seconds. + Although i's value can be wrong if overflow occurs, + this is harmless because it is just a guess. */ + __time64_t tdiff; + ckd_sub (&tdiff, transitions[timecnt - 1], timer); + ckd_add (&i, tdiff / 15778476, 0); + if (i < timecnt) { - /* Find the first transition after TIMER, and - then pick the type of the transition before it. */ - tzidx lo = 0; - tzidx hi = timecnt - 1; - /* Assume that DST is changing twice a year and guess - initial search spot from it. Half of a gregorian year - has on average 365.2425 * 86400 / 2 = 15778476 seconds. - Although i's value can be wrong if overflow occurs, - this is harmless because it is just a guess. */ - __time64_t tdiff; - ckd_sub (&tdiff, transitions[timecnt - 1], timer); - ckd_add (&i, tdiff / 15778476, 0); - if (i < timecnt) + i = timecnt - 1 - i; + if (timer < transitions[i]) { - i = timecnt - 1 - i; - if (timer < transitions[i]) - { - if (i < 10 || timer >= transitions[i - 10]) - { - /* Linear search. */ - while (timer < transitions[i - 1]) - --i; - goto found; - } - hi = i - 10; - } - else + if (i < 10 || timer >= transitions[i - 10]) { - if (timecnt - i <= 10 || timer < transitions[i + 10]) - { - /* Linear search. */ - while (timer >= transitions[i]) - ++i; - goto found; - } - lo = i + 10; + /* Linear search. */ + while (timer < transitions[i - 1]) + --i; + goto found; } + hi = i - 10; } - - /* Binary search. */ - /* assert (timer >= transitions[lo] && timer < transitions[hi]); */ - while (lo + 1 < hi) + else { - i = (lo >> 1) + (hi >> 1) + (lo & hi & 1); - if (timer < transitions[i]) - hi = i; - else - lo = i; + if (timecnt - i <= 10 || timer < transitions[i + 10]) + { + /* Linear search. */ + while (timer >= transitions[i]) + ++i; + goto found; + } + lo = i + 10; } - i = hi; - - found: - ti = type_idxs[i - 1]; } - struct ttinfo *info = &types[ti]; - unsigned char dst = info->dst; - char *tm_zone = __tzstring (&zone_names[info->idx]); - tp->tm_isdst = dst; - tp->tm_gmtoff = info->utoff; - tp->tm_zone = tm_zone; + /* Binary search. */ + /* assert (timer >= transitions[lo] && timer < transitions[hi]); */ + while (lo + 1 < hi) + { + i = (lo >> 1) + (hi >> 1) + (lo & hi & 1); + if (timer < transitions[i]) + hi = i; + else + lo = i; + } + i = hi; - /* Set tzname[isdst] too; although not required by POSIX or documented, - this is closer to what proleptic TZ does. */ - __tzname[dst] = tm_zone; + found: + ti = type_idxs[i - 1]; } + + struct ttinfo *info = &types[ti]; + unsigned char dst = info->dst; + char *tm_zone = __tzstring (&zone_names[info->idx]); + tp->tm_isdst = dst; + tp->tm_gmtoff = info->utoff; + tp->tm_zone = tm_zone; + + /* Set tzname[isdst] too; although not required by POSIX or documented, + this is closer to what proleptic TZ does. */ + __tzname[dst] = tm_zone; } weak_alias (transitions, __libc_tzfile_freemem_ptr)