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

Commit 2027519

Browse files
committed
Alignment cleanup so no more massive switch statements for alignment,
just two macros.
1 parent e15807f commit 2027519

File tree

10 files changed

+113
-333
lines changed

10 files changed

+113
-333
lines changed

src/backend/access/common/heaptuple.c

+16-181
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.43 1998/09/04 18:21:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.44 1998/09/07 05:35:27 momjian Exp $
1212
*
1313
* NOTES
1414
* The old interface functions have been converted to macros
@@ -68,44 +68,8 @@ ComputeDataSize(TupleDesc tupleDesc,
6868
if (nulls[i] != ' ')
6969
continue;
7070

71-
switch (att[i]->attlen)
72-
{
73-
case -1:
74-
75-
/*
76-
* This is the size of the disk representation and so must
77-
* include the additional sizeof long.
78-
*/
79-
if (att[i]->attalign == 'd')
80-
{
81-
data_length = DOUBLEALIGN(data_length)
82-
+ VARSIZE(DatumGetPointer(value[i]));
83-
}
84-
else
85-
{
86-
data_length = INTALIGN(data_length)
87-
+ VARSIZE(DatumGetPointer(value[i]));
88-
}
89-
break;
90-
case sizeof(char):
91-
data_length++;
92-
break;
93-
case sizeof(short):
94-
data_length = SHORTALIGN(data_length + sizeof(short));
95-
break;
96-
case sizeof(int32):
97-
data_length = INTALIGN(data_length + sizeof(int32));
98-
break;
99-
default:
100-
if (att[i]->attlen < sizeof(int32))
101-
elog(ERROR, "ComputeDataSize: attribute %d has len %d",
102-
i, att[i]->attlen);
103-
if (att[i]->attalign == 'd')
104-
data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
105-
else
106-
data_length = LONGALIGN(data_length) + att[i]->attlen;
107-
break;
108-
}
71+
data_length = att_align(data_length, att[i]->attlen, att[i]->attalign);
72+
data_length = att_addlength(data_length, att[i]->attlen, value[i]);
10973
}
11074

11175
return data_length;
@@ -160,57 +124,34 @@ DataFill(char *data,
160124
*bitP |= bitmask;
161125
}
162126

127+
data = (char *)att_align((long)data, att[i]->attlen, att[i]->attalign);
163128
switch (att[i]->attlen)
164129
{
165130
case -1:
166131
*infomask |= HEAP_HASVARLENA;
167-
if (att[i]->attalign == 'd')
168-
data = (char *) DOUBLEALIGN(data);
169-
else
170-
data = (char *) INTALIGN(data);
171132
data_length = VARSIZE(DatumGetPointer(value[i]));
172133
memmove(data, DatumGetPointer(value[i]), data_length);
173-
data += data_length;
174134
break;
175135
case sizeof(char):
176136
*data = att[i]->attbyval ?
177137
DatumGetChar(value[i]) : *((char *) value[i]);
178-
data += sizeof(char);
179138
break;
180139
case sizeof(int16):
181-
data = (char *) SHORTALIGN(data);
182140
*(short *) data = (att[i]->attbyval ?
183141
DatumGetInt16(value[i]) :
184142
*((short *) value[i]));
185-
data += sizeof(short);
186143
break;
187144
case sizeof(int32):
188-
data = (char *) INTALIGN(data);
189145
*(int32 *) data = (att[i]->attbyval ?
190146
DatumGetInt32(value[i]) :
191147
*((int32 *) value[i]));
192-
data += sizeof(int32);
193148
break;
194149
default:
195-
if (att[i]->attlen < sizeof(int32))
196-
elog(ERROR, "DataFill: attribute %d has len %d",
197-
i, att[i]->attlen);
198-
if (att[i]->attalign == 'd')
199-
{
200-
data = (char *) DOUBLEALIGN(data);
201-
memmove(data, DatumGetPointer(value[i]),
202-
att[i]->attlen);
203-
data += att[i]->attlen;
204-
}
205-
else
206-
{
207-
data = (char *) LONGALIGN(data);
208-
memmove(data, DatumGetPointer(value[i]),
209-
att[i]->attlen);
210-
data += att[i]->attlen;
211-
}
150+
memmove(data, DatumGetPointer(value[i]),
151+
att[i]->attlen);
212152
break;
213153
}
154+
data = (char *)att_addlength((long)data, att[i]->attlen, value[i]);
214155
}
215156
}
216157

@@ -557,53 +498,11 @@ nocachegetattr(HeapTuple tup,
557498
* Fix me when going to a machine with more than a four-byte
558499
* word!
559500
*/
560-
561-
switch (att[j]->attlen)
562-
{
563-
case -1:
564-
off = (att[j]->attalign == 'd') ?
565-
DOUBLEALIGN(off) : INTALIGN(off);
566-
break;
567-
case sizeof(char):
568-
break;
569-
case sizeof(short):
570-
off = SHORTALIGN(off);
571-
break;
572-
case sizeof(int32):
573-
off = INTALIGN(off);
574-
break;
575-
default:
576-
if (att[j]->attlen > sizeof(int32))
577-
off = (att[j]->attalign == 'd') ?
578-
DOUBLEALIGN(off) : LONGALIGN(off);
579-
else
580-
elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
581-
j, att[j]->attlen);
582-
break;
583-
}
501+
off = att_align(off, att[j]->attlen, att[j]->attalign);
584502

585503
att[j]->attcacheoff = off;
586504

587-
switch (att[j]->attlen)
588-
{
589-
case sizeof(char):
590-
off++;
591-
break;
592-
case sizeof(short):
593-
off += sizeof(short);
594-
break;
595-
case sizeof(int32):
596-
off += sizeof(int32);
597-
break;
598-
case -1:
599-
Assert(!VARLENA_FIXED_SIZE(att[j]) ||
600-
att[j]->atttypmod == VARSIZE(tp + off));
601-
off += VARSIZE(tp + off);
602-
break;
603-
default:
604-
off += att[j]->attlen;
605-
break;
606-
}
505+
off = att_addlength(off, att[j]->attlen, tp + off);
607506
}
608507

609508
return (Datum) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
@@ -640,84 +539,20 @@ nocachegetattr(HeapTuple tup,
640539
off = att[i]->attcacheoff;
641540
else
642541
{
643-
switch (att[i]->attlen)
644-
{
645-
case -1:
646-
off = (att[i]->attalign == 'd') ?
647-
DOUBLEALIGN(off) : INTALIGN(off);
648-
break;
649-
case sizeof(char):
650-
break;
651-
case sizeof(short):
652-
off = SHORTALIGN(off);
653-
break;
654-
case sizeof(int32):
655-
off = INTALIGN(off);
656-
break;
657-
default:
658-
if (att[i]->attlen < sizeof(int32))
659-
elog(ERROR,
660-
"nocachegetattr2: attribute %d has len %d",
661-
i, att[i]->attlen);
662-
if (att[i]->attalign == 'd')
663-
off = DOUBLEALIGN(off);
664-
else
665-
off = LONGALIGN(off);
666-
break;
667-
}
542+
off = att_align(off, att[i]->attlen, att[i]->attalign);
543+
668544
if (usecache)
669545
att[i]->attcacheoff = off;
670546
}
671547

672-
switch (att[i]->attlen)
673-
{
674-
case sizeof(char):
675-
off++;
676-
break;
677-
case sizeof(short):
678-
off += sizeof(short);
679-
break;
680-
case sizeof(int32):
681-
off += sizeof(int32);
682-
break;
683-
case -1:
684-
Assert(!VARLENA_FIXED_SIZE(att[i]) ||
685-
att[i]->atttypmod == VARSIZE(tp + off));
686-
off += VARSIZE(tp + off);
687-
if (!VARLENA_FIXED_SIZE(att[i]))
688-
usecache = false;
689-
break;
690-
default:
691-
off += att[i]->attlen;
692-
break;
693-
}
694-
}
548+
off = att_addlength(off, att[i]->attlen, tp + off);
695549

696-
switch (att[attnum]->attlen)
697-
{
698-
case -1:
699-
off = (att[attnum]->attalign == 'd') ?
700-
DOUBLEALIGN(off) : INTALIGN(off);
701-
break;
702-
case sizeof(char):
703-
break;
704-
case sizeof(short):
705-
off = SHORTALIGN(off);
706-
break;
707-
case sizeof(int32):
708-
off = INTALIGN(off);
709-
break;
710-
default:
711-
if (att[attnum]->attlen < sizeof(int32))
712-
elog(ERROR, "nocachegetattr3: attribute %d has len %d",
713-
attnum, att[attnum]->attlen);
714-
if (att[attnum]->attalign == 'd')
715-
off = DOUBLEALIGN(off);
716-
else
717-
off = LONGALIGN(off);
718-
break;
550+
if (att[i]->attlen == -1 && !VARLENA_FIXED_SIZE(att[i]))
551+
usecache = false;
719552
}
720553

554+
off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
555+
721556
return (Datum) fetchatt(&(att[attnum]), tp + off);
722557
}
723558
}

src/backend/access/common/indextuple.c

+5-74
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.31 1998/09/01 03:20:42 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.32 1998/09/07 05:35:28 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -300,30 +300,7 @@ nocache_index_getattr(IndexTuple tup,
300300
* word!
301301
*/
302302

303-
switch (att[j]->attlen)
304-
{
305-
case -1:
306-
off = (att[j]->attalign == 'd') ?
307-
DOUBLEALIGN(off) : INTALIGN(off);
308-
break;
309-
case sizeof(char):
310-
break;
311-
case sizeof(short):
312-
off = SHORTALIGN(off);
313-
break;
314-
case sizeof(int32):
315-
off = INTALIGN(off);
316-
break;
317-
default:
318-
if (att[j]->attlen > sizeof(int32))
319-
off = (att[j]->attalign == 'd') ?
320-
DOUBLEALIGN(off) : LONGALIGN(off);
321-
else
322-
elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
323-
j, att[j]->attlen);
324-
break;
325-
326-
}
303+
off = att_align(off, att[j]->attlen, att[j]->attalign);
327304

328305
att[j]->attcacheoff = off;
329306

@@ -365,31 +342,8 @@ nocache_index_getattr(IndexTuple tup,
365342
off = att[i]->attcacheoff;
366343
else
367344
{
368-
switch (att[i]->attlen)
369-
{
370-
case -1:
371-
off = (att[i]->attalign == 'd') ?
372-
DOUBLEALIGN(off) : INTALIGN(off);
373-
break;
374-
case sizeof(char):
375-
break;
376-
case sizeof(short):
377-
off = SHORTALIGN(off);
378-
break;
379-
case sizeof(int32):
380-
off = INTALIGN(off);
381-
break;
382-
default:
383-
if (att[i]->attlen < sizeof(int32))
384-
elog(ERROR,
385-
"nocachegetiattr2: attribute %d has len %d",
386-
i, att[i]->attlen);
387-
if (att[i]->attalign == 'd')
388-
off = DOUBLEALIGN(off);
389-
else
390-
off = LONGALIGN(off);
391-
break;
392-
}
345+
off = att_align(off, att[i]->attlen, att[i]->attalign);
346+
393347
if (usecache)
394348
att[i]->attcacheoff = off;
395349
}
@@ -418,30 +372,7 @@ nocache_index_getattr(IndexTuple tup,
418372
}
419373
}
420374

421-
switch (att[attnum]->attlen)
422-
{
423-
case -1:
424-
off = (att[attnum]->attalign == 'd') ?
425-
DOUBLEALIGN(off) : INTALIGN(off);
426-
break;
427-
case sizeof(char):
428-
break;
429-
case sizeof(short):
430-
off = SHORTALIGN(off);
431-
break;
432-
case sizeof(int32):
433-
off = INTALIGN(off);
434-
break;
435-
default:
436-
if (att[attnum]->attlen < sizeof(int32))
437-
elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
438-
attnum, att[attnum]->attlen);
439-
if (att[attnum]->attalign == 'd')
440-
off = DOUBLEALIGN(off);
441-
else
442-
off = LONGALIGN(off);
443-
break;
444-
}
375+
off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
445376

446377
return (Datum) fetchatt(&att[attnum], tp + off);
447378
}

src/backend/access/index/indexam.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.26 1998/09/02 23:05:21 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.27 1998/09/07 05:35:30 momjian Exp $
1111
*
1212
* INTERFACE ROUTINES
1313
* index_open - open an index relation by relationId
@@ -384,9 +384,7 @@ GetIndexValue(HeapTuple tuple,
384384
*attNull = FALSE;
385385
}
386386
else
387-
{
388-
returnVal = heap_getattr(tuple, attrNums[attOff],
389-
hTupDesc, attNull);
390-
}
387+
returnVal = heap_getattr(tuple, attrNums[attOff], hTupDesc, attNull);
388+
391389
return returnVal;
392390
}

0 commit comments

Comments
 (0)