So...in the vein of my last mail, I have tried to create another patch
for refactoring out some of the HAVE_INT64_TIMESTAMP ifdefs in the
code in timestamp.c. I have attached the patch. Please let me know if
this patch is acceptable and what I can do to continue this effort.

Thanks,
wt
From 77db4f84999161c0c7ba8ded78636512cc719878 Mon Sep 17 00:00:00 2001
From: Warren Turkal <[EMAIL PROTECTED]>
Date: Wed, 9 Jan 2008 00:19:46 -0800
Subject: [PATCH] Add PackedTime typedef.

The PackedTime type is meant to be a type that holds the hour, minute,
second, and fractional seconds part of the time. The actual primitive
type that the PackedTime type uses is determined by the
HAVE_INT64_TIMESTAMP define.

I have also changed some of the instances of variable declaratations
for times to use the PackedTime type instead of the primitive types.
---
 src/backend/utils/adt/timestamp.c |   21 ++++++---------------
 src/include/utils/timestamp.h     |    9 +++------
 2 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 2883caf..1a4c247 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -44,11 +44,7 @@
 TimestampTz PgStartTime;
 
 
-#ifdef HAVE_INT64_TIMESTAMP
-static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#else
-static double time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#endif
+static PackedTime time2t(const int hour, const int min, const int sec, const fsec_t fsec);
 static int	EncodeSpecialTimestamp(Timestamp dt, char *str);
 static Timestamp dt2local(Timestamp dt, int timezone);
 static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
@@ -1539,11 +1535,10 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
 {
 #ifdef HAVE_INT64_TIMESTAMP
 	int			date;
-	int64		time;
 #else
-	double		date,
-				time;
+	double		date;
 #endif
+	PackedTime time;
 
 	/* Julian day routines are not correct for negative Julian days */
 	if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
@@ -1648,19 +1643,15 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
 	return 0;
 }
 
-#ifdef HAVE_INT64_TIMESTAMP
-static int64
+static PackedTime
 time2t(const int hour, const int min, const int sec, const fsec_t fsec)
 {
+#ifdef HAVE_INT64_TIMESTAMP
 	return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
-}	/* time2t() */
 #else
-static double
-time2t(const int hour, const int min, const int sec, const fsec_t fsec)
-{
 	return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
-}	/* time2t() */
 #endif
+}	/* time2t() */
 
 static Timestamp
 dt2local(Timestamp dt, int tz)
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index 6eec76d..945b970 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -36,20 +36,17 @@
 #ifdef HAVE_INT64_TIMESTAMP
 typedef int64 Timestamp;
 typedef int64 TimestampTz;
+typedef int64 PackedTime;
 #else
 typedef double Timestamp;
 typedef double TimestampTz;
+typedef double PackedTime;
 #endif
 
 typedef struct
 {
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		time;			/* all time units other than days, months and
-								 * years */
-#else
-	double		time;			/* all time units other than days, months and
+	PackedTime	time;			/* all time units other than days, months and
 								 * years */
-#endif
 	int32		day;			/* days, after time for alignment */
 	int32		month;			/* months and years, after time for alignment */
 } Interval;
-- 
1.5.3.7

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to