1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Reduce the size of the compiled binary by a couple of hundred bytes by

using a thigher packing of a transformation table in date.c.
Suggested by [forum:/forumpost/4f6efbb2a9|forum post 4f6efbb2a9].

FossilOrigin-Name: c75ba4fa644d338d22813c17172b9975411fe6197e07fd584e3209e3beb78036
This commit is contained in:
drh
2021-12-23 00:16:06 +00:00
parent 8b6dfc474b
commit b131bf7039
3 changed files with 24 additions and 22 deletions

View File

@@ -617,18 +617,17 @@ static sqlite3_int64 localtimeOffset(
** of several units of time.
*/
static const struct {
u8 eType; /* Transformation type code */
u8 nName; /* Length of th name */
char *zName; /* Name of the transformation */
double rLimit; /* Maximum NNN value for this transform */
double rXform; /* Constant used for this transform */
u8 nName; /* Length of the name */
char zName[7]; /* Name of the transformation */
float rLimit; /* Maximum NNN value for this transform */
float rXform; /* Constant used for this transform */
} aXformType[] = {
{ 0, 6, "second", 464269060800.0, 1000.0 },
{ 0, 6, "minute", 7737817680.0, 60000.0 },
{ 0, 4, "hour", 128963628.0, 3600000.0 },
{ 0, 3, "day", 5373485.0, 86400000.0 },
{ 1, 5, "month", 176546.0, 2592000000.0 },
{ 2, 4, "year", 14713.0, 31536000000.0 },
{ 6, "second", 4.6427e+14, 1.0 },
{ 6, "minute", 7.7379e+12, 60.0 },
{ 4, "hour", 1.2897e+11, 3600.0 },
{ 3, "day", 5373485.0, 86400.0 },
{ 5, "month", 176546.0, 2592000.0 },
{ 4, "year", 14713.0, 31536000.0 },
};
/*
@@ -865,9 +864,10 @@ static int parseModifier(
&& sqlite3_strnicmp(aXformType[i].zName, z, n)==0
&& r>-aXformType[i].rLimit && r<aXformType[i].rLimit
){
switch( aXformType[i].eType ){
case 1: { /* Special processing to add months */
switch( i ){
case 4: { /* Special processing to add months */
int x;
assert( strcmp(aXformType[i].zName,"month")==0 );
computeYMD_HMS(p);
p->M += (int)r;
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
@@ -877,8 +877,9 @@ static int parseModifier(
r -= (int)r;
break;
}
case 2: { /* Special processing to add years */
case 5: { /* Special processing to add years */
int y = (int)r;
assert( strcmp(aXformType[i].zName,"year")==0 );
computeYMD_HMS(p);
p->Y += y;
p->validJD = 0;
@@ -887,7 +888,7 @@ static int parseModifier(
}
}
computeJD(p);
p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder);
rc = 0;
break;
}