1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Remove now-dead code for !HAVE_INT64_TIMESTAMP.

This is a basically mechanical removal of #ifdef HAVE_INT64_TIMESTAMP
tests and the negative-case controlled code.

Discussion: https://postgr.es/m/26788.1487455319@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2017-02-23 14:04:43 -05:00
parent d28aafb6dd
commit b9d092c962
26 changed files with 28 additions and 1298 deletions

View File

@ -43,11 +43,6 @@ static int DecodeTime(char *str, int fmask, int range,
static const datetkn *datebsearch(const char *key, const datetkn *base, int nel);
static int DecodeDate(char *str, int fmask, int *tmask, bool *is2digits,
struct pg_tm * tm);
#ifndef HAVE_INT64_TIMESTAMP
static char *TrimTrailingZeros(char *str);
#endif /* HAVE_INT64_TIMESTAMP */
static char *AppendSeconds(char *cp, int sec, fsec_t fsec,
int precision, bool fillzeros);
static void AdjustFractSeconds(double frac, struct pg_tm * tm, fsec_t *fsec,
@ -401,28 +396,6 @@ GetCurrentTimeUsec(struct pg_tm * tm, fsec_t *fsec, int *tzp)
}
/* TrimTrailingZeros()
* ... resulting from printing numbers with full precision.
*
* Returns a pointer to the new end of string. No NUL terminator is put
* there; callers are responsible for NUL terminating str themselves.
*
* Before Postgres 8.4, this always left at least 2 fractional digits,
* but conversations on the lists suggest this isn't desired
* since showing '0.10' is misleading with values of precision(1).
*/
#ifndef HAVE_INT64_TIMESTAMP
static char *
TrimTrailingZeros(char *str)
{
int len = strlen(str);
while (len > 1 && *(str + len - 1) == '0' && *(str + len - 2) != '.')
len--;
return str + len;
}
#endif /* HAVE_INT64_TIMESTAMP */
/*
* Append seconds and fractional seconds (if any) at *cp.
*
@ -439,14 +412,12 @@ AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
{
Assert(precision >= 0);
#ifdef HAVE_INT64_TIMESTAMP
/* fsec_t is just an int32 */
if (fillzeros)
cp = pg_ltostr_zeropad(cp, Abs(sec), 2);
else
cp = pg_ltostr(cp, Abs(sec));
/* fsec_t is just an int32 */
if (fsec != 0)
{
int32 value = Abs(fsec);
@ -490,25 +461,6 @@ AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
}
else
return cp;
#else
/* fsec_t is a double */
if (fsec == 0)
{
if (fillzeros)
return pg_ltostr_zeropad(cp, Abs(sec), 2);
else
return pg_ltostr(cp, Abs(sec));
}
else
{
if (fillzeros)
sprintf(cp, "%0*.*f", precision + 3, precision, fabs(sec + fsec));
else
sprintf(cp, "%.*f", precision, fabs(sec + fsec));
return TrimTrailingZeros(cp);
}
#endif /* HAVE_INT64_TIMESTAMP */
}
@ -521,14 +473,6 @@ AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
static char *
AppendTimestampSeconds(char *cp, struct pg_tm * tm, fsec_t fsec)
{
/*
* In float mode, don't print fractional seconds before 1 AD, since it's
* unlikely there's any precision left ...
*/
#ifndef HAVE_INT64_TIMESTAMP
if (tm->tm_year <= 0)
fsec = 0;
#endif
return AppendSeconds(cp, tm->tm_sec, fsec, MAX_TIMESTAMP_PRECISION, true);
}
@ -547,11 +491,7 @@ AdjustFractSeconds(double frac, struct pg_tm * tm, fsec_t *fsec, int scale)
sec = (int) frac;
tm->tm_sec += sec;
frac -= sec;
#ifdef HAVE_INT64_TIMESTAMP
*fsec += rint(frac * 1000000);
#else
*fsec += frac;
#endif
}
/* As above, but initial scale produces days */
@ -582,11 +522,7 @@ ParseFractionalSecond(char *cp, fsec_t *fsec)
/* check for parse failure */
if (*cp != '\0' || errno != 0)
return DTERR_BAD_FORMAT;
#ifdef HAVE_INT64_TIMESTAMP
*fsec = rint(frac * 1000000);
#else
*fsec = frac;
#endif
return 0;
}
@ -1162,12 +1098,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
time = strtod(cp, &cp);
if (*cp != '\0' || errno != 0)
return DTERR_BAD_FORMAT;
#ifdef HAVE_INT64_TIMESTAMP
time *= USECS_PER_DAY;
#else
time *= SECS_PER_DAY;
#endif
dt2time(time,
&tm->tm_hour, &tm->tm_min,
&tm->tm_sec, fsec);
@ -2070,12 +2001,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
time = strtod(cp, &cp);
if (*cp != '\0' || errno != 0)
return DTERR_BAD_FORMAT;
#ifdef HAVE_INT64_TIMESTAMP
time *= USECS_PER_DAY;
#else
time *= SECS_PER_DAY;
#endif
dt2time(time,
&tm->tm_hour, &tm->tm_min,
&tm->tm_sec, fsec);
@ -2338,12 +2264,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
/* test for > 24:00:00 */
(tm->tm_hour == HOURS_PER_DAY &&
(tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0)) ||
#ifdef HAVE_INT64_TIMESTAMP
*fsec < INT64CONST(0) || *fsec > USECS_PER_SEC
#else
*fsec < 0 || *fsec > 1
#endif
)
*fsec < INT64CONST(0) || *fsec > USECS_PER_SEC)
return DTERR_FIELD_OVERFLOW;
if ((fmask & DTK_TIME_M) != DTK_TIME_M)
@ -2695,18 +2616,11 @@ DecodeTime(char *str, int fmask, int range,
return DTERR_BAD_FORMAT;
/* do a sanity check */
#ifdef HAVE_INT64_TIMESTAMP
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > MINS_PER_HOUR - 1 ||
tm->tm_sec < 0 || tm->tm_sec > SECS_PER_MINUTE ||
*fsec < INT64CONST(0) ||
*fsec > USECS_PER_SEC)
return DTERR_FIELD_OVERFLOW;
#else
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > MINS_PER_HOUR - 1 ||
tm->tm_sec < 0 || tm->tm_sec > SECS_PER_MINUTE ||
*fsec < 0 || *fsec > 1)
return DTERR_FIELD_OVERFLOW;
#endif
return 0;
}
@ -2923,11 +2837,7 @@ DecodeNumberField(int len, char *str, int fmask,
frac = strtod(cp, NULL);
if (errno != 0)
return DTERR_BAD_FORMAT;
#ifdef HAVE_INT64_TIMESTAMP
*fsec = rint(frac * 1000000);
#else
*fsec = frac;
#endif
/* Now truncate off the fraction for further processing */
*cp = '\0';
len = strlen(str);
@ -3336,11 +3246,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
switch (type)
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
*fsec += rint(val + fval);
#else
*fsec += (val + fval) * 1e-6;
#endif
tmask = DTK_M(MICROSECOND);
break;
@ -3348,21 +3254,13 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
/* avoid overflowing the fsec field */
tm->tm_sec += val / 1000;
val -= (val / 1000) * 1000;
#ifdef HAVE_INT64_TIMESTAMP
*fsec += rint((val + fval) * 1000);
#else
*fsec += (val + fval) * 1e-3;
#endif
tmask = DTK_M(MILLISECOND);
break;
case DTK_SECOND:
tm->tm_sec += val;
#ifdef HAVE_INT64_TIMESTAMP
*fsec += rint(fval * 1000000);
#else
*fsec += fval;
#endif
/*
* If any subseconds were specified, consider this
@ -3484,12 +3382,8 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
{
int sec;
#ifdef HAVE_INT64_TIMESTAMP
sec = *fsec / USECS_PER_SEC;
*fsec -= sec * USECS_PER_SEC;
#else
TMODULO(*fsec, sec, 1.0);
#endif
tm->tm_sec += sec;
}