Skip to content

Commit e94c1a5

Browse files
committed
Avoid unnecessary division in interval_cmp_value().
Splitting the time field into days and microseconds is pretty useless when we're just going to recombine those values. It's unclear if anyone will notice the speedup in real-world cases, but a cycle shaved is a cycle earned. Discussion: https://postgr.es/m/2629129.1632675713@sss.pgh.pa.us
1 parent 7c1d8a2 commit e94c1a5

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,20 +2352,17 @@ static inline INT128
23522352
interval_cmp_value(const Interval *interval)
23532353
{
23542354
INT128 span;
2355-
int64 dayfraction;
23562355
int64 days;
23572356

23582357
/*
2359-
* Separate time field into days and dayfraction, then add the month and
2360-
* day fields to the days part. We cannot overflow int64 days here.
2358+
* Combine the month and day fields into an integral number of days.
2359+
* Because the inputs are int32, int64 arithmetic suffices here.
23612360
*/
2362-
dayfraction = interval->time % USECS_PER_DAY;
2363-
days = interval->time / USECS_PER_DAY;
2364-
days += interval->month * INT64CONST(30);
2361+
days = interval->month * INT64CONST(30);
23652362
days += interval->day;
23662363

2367-
/* Widen dayfraction to 128 bits */
2368-
span = int64_to_int128(dayfraction);
2364+
/* Widen time field to 128 bits */
2365+
span = int64_to_int128(interval->time);
23692366

23702367
/* Scale up days to microseconds, forming a 128-bit product */
23712368
int128_add_int64_mul_int64(&span, days, USECS_PER_DAY);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy