Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d0583a

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'seither int64 or double as appropriate, and in most usages will be measuredin microseconds or seconds the same as Timestamp. We don't call itTimestamp, though, since the value doesn't necessarily represent an absolutetime instant.Warren Turkal
1 parent6b0706a commit2d0583a

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
staticint
18391839
timetz2tm(TimeTzADT*time,structpg_tm*tm,fsec_t*fsec,int*tzp)
18401840
{
1841-
#ifdefHAVE_INT64_TIMESTAMP
1842-
int64trem=time->time;
1841+
TimeOffsettrem=time->time;
18431842

1843+
#ifdefHAVE_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-
doubletrem=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
staticint
18961894
timetz_cmp_internal(TimeTzADT*time1,TimeTzADT*time2)
18971895
{
1898-
/* Primary sort is by true (GMT-equivalent) time */
1899-
#ifdefHAVE_INT64_TIMESTAMP
1900-
int64t1,
1896+
TimeOffsett1,
19011897
t2;
19021898

1899+
/* Primary sort is by true (GMT-equivalent) time */
1900+
#ifdefHAVE_INT64_TIMESTAMP
19031901
t1=time1->time+ (time1->zone*USECS_PER_SEC);
19041902
t2=time2->time+ (time2->zone*USECS_PER_SEC);
19051903
#else
1906-
doublet1,
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
intyear,
832832
month,
833833
day;
834-
835-
#ifdefHAVE_INT64_TIMESTAMP
836-
int64span;
837-
#else
838-
doublespan;
839-
#endif
834+
TimeOffsetspan;
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
TimestampTzPgStartTime;
4545

4646

47-
#ifdefHAVE_INT64_TIMESTAMP
48-
staticint64time2t(constinthour,constintmin,constintsec,constfsec_tfsec);
49-
#else
50-
staticdoubletime2t(constinthour,constintmin,constintsec,constfsec_tfsec);
51-
#endif
47+
staticTimeOffsettime2t(constinthour,constintmin,constintsec,constfsec_tfsec);
5248
staticintEncodeSpecialTimestamp(Timestampdt,char*str);
5349
staticTimestampdt2local(Timestampdt,inttimezone);
5450
staticvoidAdjustTimestampForTypmod(Timestamp*time,int32typmod);
@@ -977,11 +973,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
977973
}
978974
elseif (range==INTERVAL_MASK(MINUTE))
979975
{
980-
#ifdefHAVE_INT64_TIMESTAMP
981-
int64hour;
982-
#else
983-
doublehour;
984-
#endif
976+
TimeOffsethour;
985977

986978
interval->month=0;
987979
interval->day=0;
@@ -998,11 +990,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
998990
}
999991
elseif (range==INTERVAL_MASK(SECOND))
1000992
{
1001-
#ifdefHAVE_INT64_TIMESTAMP
1002-
int64minute;
1003-
#else
1004-
doubleminute;
1005-
#endif
993+
TimeOffsetminute;
1006994

1007995
interval->month=0;
1008996
interval->day=0;
@@ -1076,11 +1064,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
10761064
elseif (range== (INTERVAL_MASK(MINUTE) |
10771065
INTERVAL_MASK(SECOND)))
10781066
{
1079-
#ifdefHAVE_INT64_TIMESTAMP
1080-
int64hour;
1081-
#else
1082-
doublehour;
1083-
#endif
1067+
TimeOffsethour;
10841068

10851069
interval->month=0;
10861070
interval->day=0;
@@ -1342,11 +1326,7 @@ timestamptz_to_str(TimestampTz t)
13421326
void
13431327
dt2time(Timestampjd,int*hour,int*min,int*sec,fsec_t*fsec)
13441328
{
1345-
#ifdefHAVE_INT64_TIMESTAMP
1346-
int64time;
1347-
#else
1348-
doubletime;
1349-
#endif
1329+
TimeOffsettime;
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(structpg_tm*tm,fsec_tfsec,int*tzp,Timestamp*result)
15491529
{
1550-
#ifdefHAVE_INT64_TIMESTAMP
1551-
intdate;
1552-
int64time;
1553-
#else
1554-
doubledate,
1555-
time;
1556-
#endif
1530+
TimeOffsetdate;
1531+
TimeOffsettime;
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(Intervalspan,structpg_tm*tm,fsec_t*fsec)
15981573
{
1599-
#ifdefHAVE_INT64_TIMESTAMP
1600-
int64time;
1601-
int64tfrac;
1602-
#else
1603-
doubletime;
1604-
doubletfrac;
1605-
#endif
1574+
TimeOffsettime;
1575+
TimeOffsettfrac;
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
return0;
16591629
}
16601630

1661-
#ifdefHAVE_INT64_TIMESTAMP
1662-
staticint64
1631+
staticTimeOffset
16631632
time2t(constinthour,constintmin,constintsec,constfsec_tfsec)
16641633
{
1634+
#ifdefHAVE_INT64_TIMESTAMP
16651635
return (((((hour*MINS_PER_HOUR)+min)*SECS_PER_MINUTE)+sec)*USECS_PER_SEC)+fsec;
1666-
}/* time2t() */
16671636
#else
1668-
staticdouble
1669-
time2t(constinthour,constintmin,constintsec,constfsec_tfsec)
1670-
{
16711637
return (((hour*MINS_PER_HOUR)+min)*SECS_PER_MINUTE)+sec+fsec;
1672-
}/* time2t() */
16731638
#endif
1639+
}
16741640

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

16861652

16871653
/*****************************************************************************
@@ -2042,13 +2008,8 @@ timestamptz_cmp_timestamp(PG_FUNCTION_ARGS)
20422008
staticint
20432009
interval_cmp_internal(Interval*interval1,Interval*interval2)
20442010
{
2045-
#ifdefHAVE_INT64_TIMESTAMP
2046-
int64span1,
2047-
span2;
2048-
#else
2049-
doublespan1,
2011+
TimeOffsetspan1,
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-
#ifdefHAVE_INT64_TIMESTAMP
2392-
int64wholeday;
2393-
#else
2394-
doublewholeday;
2395-
#endif
2351+
TimeOffsetwholeday;
23962352
int32wholemonth;
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-
#ifdefHAVE_INT64_TIMESTAMP
2464-
int64wholeday;
2465-
#else
2466-
doublewholeday;
2467-
#endif
2418+
TimeOffsetwholeday;
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
typedefstruct
3131
{
32-
#ifdefHAVE_INT64_TIMESTAMP
33-
int64time;/* all time units other than months and years */
34-
#else
35-
doubletime;/* all time units other than months and years */
36-
#endif
32+
TimeADTtime;/* all time units other than months and years */
3733
int32zone;/* numeric time zone, in seconds */
3834
}TimeTzADT;
3935

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

5956
#defineMAX_TIME_PRECISION 10
6057

@@ -69,6 +66,7 @@ typedef struct
6966
#defineDateADTGetDatum(X) Int32GetDatum(X)
7067
#defineTimeADTGetDatum(X) Float8GetDatum(X)
7168
#defineTimeTzADTPGetDatum(X) PointerGetDatum(X)
69+
7270
#endif/* HAVE_INT64_TIMESTAMP */
7371

7472
#definePG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp