Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2d0583a

Browse files
committed
Get rid of a bunch of #ifdef HAVE_INT64_TIMESTAMP conditionals by inventing
a new typedef TimeOffset to represent an intermediate time value. It's either int64 or double as appropriate, and in most usages will be measured in microseconds or seconds the same as Timestamp. We don't call it Timestamp, though, since the value doesn't necessarily represent an absolute time instant. Warren Turkal
1 parent 6b0706a commit 2d0583a

File tree

5 files changed

+57
-113
lines changed

5 files changed

+57
-113
lines changed

src/backend/utils/adt/date.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.139 2008/02/17 02:09:28 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.140 2008/03/21 01:31:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1838,18 +1838,16 @@ timetztypmodout(PG_FUNCTION_ARGS)
18381838
static int
18391839
timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
18401840
{
1841-
#ifdef HAVE_INT64_TIMESTAMP
1842-
int64 trem = time->time;
1841+
TimeOffset trem = time->time;
18431842

1843+
#ifdef HAVE_INT64_TIMESTAMP
18441844
tm->tm_hour = trem / USECS_PER_HOUR;
18451845
trem -= tm->tm_hour * USECS_PER_HOUR;
18461846
tm->tm_min = trem / USECS_PER_MINUTE;
18471847
trem -= tm->tm_min * USECS_PER_MINUTE;
18481848
tm->tm_sec = trem / USECS_PER_SEC;
18491849
*fsec = trem - tm->tm_sec * USECS_PER_SEC;
18501850
#else
1851-
double trem = time->time;
1852-
18531851
recalc:
18541852
TMODULO(trem, tm->tm_hour, (double) SECS_PER_HOUR);
18551853
TMODULO(trem, tm->tm_min, (double) SECS_PER_MINUTE);
@@ -1895,17 +1893,14 @@ timetz_scale(PG_FUNCTION_ARGS)
18951893
static int
18961894
timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
18971895
{
1898-
/* Primary sort is by true (GMT-equivalent) time */
1899-
#ifdef HAVE_INT64_TIMESTAMP
1900-
int64 t1,
1896+
TimeOffset t1,
19011897
t2;
19021898

1899+
/* Primary sort is by true (GMT-equivalent) time */
1900+
#ifdef HAVE_INT64_TIMESTAMP
19031901
t1 = time1->time + (time1->zone * USECS_PER_SEC);
19041902
t2 = time2->time + (time2->zone * USECS_PER_SEC);
19051903
#else
1906-
double t1,
1907-
t2;
1908-
19091904
t1 = time1->time + time1->zone;
19101905
t2 = time2->time + time2->zone;
19111906
#endif

src/backend/utils/adt/nabstime.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.153 2008/02/17 02:09:28 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.154 2008/03/21 01:31:42 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -831,12 +831,7 @@ interval_reltime(PG_FUNCTION_ARGS)
831831
int year,
832832
month,
833833
day;
834-
835-
#ifdef HAVE_INT64_TIMESTAMP
836-
int64 span;
837-
#else
838-
double span;
839-
#endif
834+
TimeOffset span;
840835

841836
year = interval->month / MONTHS_PER_YEAR;
842837
month = interval->month % MONTHS_PER_YEAR;

src/backend/utils/adt/timestamp.c

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.185 2008/02/17 02:09:28 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.186 2008/03/21 01:31:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,11 +44,7 @@
4444
TimestampTz PgStartTime;
4545

4646

47-
#ifdef HAVE_INT64_TIMESTAMP
48-
static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec);
49-
#else
50-
static double time2t(const int hour, const int min, const int sec, const fsec_t fsec);
51-
#endif
47+
static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec);
5248
static int EncodeSpecialTimestamp(Timestamp dt, char *str);
5349
static Timestamp dt2local(Timestamp dt, int timezone);
5450
static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
@@ -977,11 +973,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
977973
}
978974
else if (range == INTERVAL_MASK(MINUTE))
979975
{
980-
#ifdef HAVE_INT64_TIMESTAMP
981-
int64 hour;
982-
#else
983-
double hour;
984-
#endif
976+
TimeOffset hour;
985977

986978
interval->month = 0;
987979
interval->day = 0;
@@ -998,11 +990,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
998990
}
999991
else if (range == INTERVAL_MASK(SECOND))
1000992
{
1001-
#ifdef HAVE_INT64_TIMESTAMP
1002-
int64 minute;
1003-
#else
1004-
double minute;
1005-
#endif
993+
TimeOffset minute;
1006994

1007995
interval->month = 0;
1008996
interval->day = 0;
@@ -1076,11 +1064,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
10761064
else if (range == (INTERVAL_MASK(MINUTE) |
10771065
INTERVAL_MASK(SECOND)))
10781066
{
1079-
#ifdef HAVE_INT64_TIMESTAMP
1080-
int64 hour;
1081-
#else
1082-
double hour;
1083-
#endif
1067+
TimeOffset hour;
10841068

10851069
interval->month = 0;
10861070
interval->day = 0;
@@ -1342,11 +1326,7 @@ timestamptz_to_str(TimestampTz t)
13421326
void
13431327
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
13441328
{
1345-
#ifdef HAVE_INT64_TIMESTAMP
1346-
int64 time;
1347-
#else
1348-
double time;
1349-
#endif
1329+
TimeOffset time;
13501330

13511331
time = jd;
13521332

@@ -1547,13 +1527,8 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
15471527
int
15481528
tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
15491529
{
1550-
#ifdef HAVE_INT64_TIMESTAMP
1551-
int date;
1552-
int64 time;
1553-
#else
1554-
double date,
1555-
time;
1556-
#endif
1530+
TimeOffset date;
1531+
TimeOffset time;
15571532

15581533
/* Julian day routines are not correct for negative Julian days */
15591534
if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
@@ -1596,13 +1571,8 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
15961571
int
15971572
interval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec)
15981573
{
1599-
#ifdef HAVE_INT64_TIMESTAMP
1600-
int64 time;
1601-
int64 tfrac;
1602-
#else
1603-
double time;
1604-
double tfrac;
1605-
#endif
1574+
TimeOffset time;
1575+
TimeOffset tfrac;
16061576

16071577
tm->tm_year = span.month / MONTHS_PER_YEAR;
16081578
tm->tm_mon = span.month % MONTHS_PER_YEAR;
@@ -1658,19 +1628,15 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
16581628
return 0;
16591629
}
16601630

1661-
#ifdef HAVE_INT64_TIMESTAMP
1662-
static int64
1631+
static TimeOffset
16631632
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
16641633
{
1634+
#ifdef HAVE_INT64_TIMESTAMP
16651635
return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
1666-
} /* time2t() */
16671636
#else
1668-
static double
1669-
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
1670-
{
16711637
return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
1672-
} /* time2t() */
16731638
#endif
1639+
}
16741640

16751641
static Timestamp
16761642
dt2local(Timestamp dt, int tz)
@@ -1681,7 +1647,7 @@ dt2local(Timestamp dt, int tz)
16811647
dt -= tz;
16821648
#endif
16831649
return dt;
1684-
} /* dt2local() */
1650+
}
16851651

16861652

16871653
/*****************************************************************************
@@ -2042,13 +2008,8 @@ timestamptz_cmp_timestamp(PG_FUNCTION_ARGS)
20422008
static int
20432009
interval_cmp_internal(Interval *interval1, Interval *interval2)
20442010
{
2045-
#ifdef HAVE_INT64_TIMESTAMP
2046-
int64 span1,
2047-
span2;
2048-
#else
2049-
double span1,
2011+
TimeOffset span1,
20502012
span2;
2051-
#endif
20522013

20532014
span1 = interval1->time;
20542015
span2 = interval2->time;
@@ -2387,12 +2348,7 @@ interval_justify_interval(PG_FUNCTION_ARGS)
23872348
{
23882349
Interval *span = PG_GETARG_INTERVAL_P(0);
23892350
Interval *result;
2390-
2391-
#ifdef HAVE_INT64_TIMESTAMP
2392-
int64 wholeday;
2393-
#else
2394-
double wholeday;
2395-
#endif
2351+
TimeOffset wholeday;
23962352
int32 wholemonth;
23972353

23982354
result = (Interval *) palloc(sizeof(Interval));
@@ -2459,12 +2415,7 @@ interval_justify_hours(PG_FUNCTION_ARGS)
24592415
{
24602416
Interval *span = PG_GETARG_INTERVAL_P(0);
24612417
Interval *result;
2462-
2463-
#ifdef HAVE_INT64_TIMESTAMP
2464-
int64 wholeday;
2465-
#else
2466-
double wholeday;
2467-
#endif
2418+
TimeOffset wholeday;
24682419

24692420
result = (Interval *) palloc(sizeof(Interval));
24702421
result->month = span->month;

src/include/utils/date.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/date.h,v 1.39 2008/01/01 19:45:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/date.h,v 1.40 2008/03/21 01:31:43 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,11 +29,7 @@ typedef float8 TimeADT;
2929

3030
typedef struct
3131
{
32-
#ifdef HAVE_INT64_TIMESTAMP
33-
int64 time; /* all time units other than months and years */
34-
#else
35-
double time; /* all time units other than months and years */
36-
#endif
32+
TimeADT time; /* all time units other than months and years */
3733
int32 zone; /* numeric time zone, in seconds */
3834
} TimeTzADT;
3935

@@ -54,7 +50,8 @@ typedef struct
5450
#define DateADTGetDatum(X) Int32GetDatum(X)
5551
#define TimeADTGetDatum(X) Int64GetDatum(X)
5652
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
57-
#else
53+
54+
#else /* !HAVE_INT64_TIMESTAMP */
5855

5956
#define MAX_TIME_PRECISION 10
6057

@@ -69,6 +66,7 @@ typedef struct
6966
#define DateADTGetDatum(X) Int32GetDatum(X)
7067
#define TimeADTGetDatum(X) Float8GetDatum(X)
7168
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
69+
7270
#endif /* HAVE_INT64_TIMESTAMP */
7371

7472
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))

0 commit comments

Comments
 (0)