|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | * NOTES
|
14 | 14 | * The old interface functions have been converted to macros
|
@@ -68,44 +68,8 @@ ComputeDataSize(TupleDesc tupleDesc,
|
68 | 68 | if (nulls[i] != ' ')
|
69 | 69 | continue;
|
70 | 70 |
|
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]); |
109 | 73 | }
|
110 | 74 |
|
111 | 75 | return data_length;
|
@@ -160,57 +124,34 @@ DataFill(char *data,
|
160 | 124 | *bitP |= bitmask;
|
161 | 125 | }
|
162 | 126 |
|
| 127 | + data = (char *)att_align((long)data, att[i]->attlen, att[i]->attalign); |
163 | 128 | switch (att[i]->attlen)
|
164 | 129 | {
|
165 | 130 | case -1:
|
166 | 131 | *infomask |= HEAP_HASVARLENA;
|
167 |
| - if (att[i]->attalign == 'd') |
168 |
| - data = (char *) DOUBLEALIGN(data); |
169 |
| - else |
170 |
| - data = (char *) INTALIGN(data); |
171 | 132 | data_length = VARSIZE(DatumGetPointer(value[i]));
|
172 | 133 | memmove(data, DatumGetPointer(value[i]), data_length);
|
173 |
| - data += data_length; |
174 | 134 | break;
|
175 | 135 | case sizeof(char):
|
176 | 136 | *data = att[i]->attbyval ?
|
177 | 137 | DatumGetChar(value[i]) : *((char *) value[i]);
|
178 |
| - data += sizeof(char); |
179 | 138 | break;
|
180 | 139 | case sizeof(int16):
|
181 |
| - data = (char *) SHORTALIGN(data); |
182 | 140 | *(short *) data = (att[i]->attbyval ?
|
183 | 141 | DatumGetInt16(value[i]) :
|
184 | 142 | *((short *) value[i]));
|
185 |
| - data += sizeof(short); |
186 | 143 | break;
|
187 | 144 | case sizeof(int32):
|
188 |
| - data = (char *) INTALIGN(data); |
189 | 145 | *(int32 *) data = (att[i]->attbyval ?
|
190 | 146 | DatumGetInt32(value[i]) :
|
191 | 147 | *((int32 *) value[i]));
|
192 |
| - data += sizeof(int32); |
193 | 148 | break;
|
194 | 149 | 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); |
212 | 152 | break;
|
213 | 153 | }
|
| 154 | + data = (char *)att_addlength((long)data, att[i]->attlen, value[i]); |
214 | 155 | }
|
215 | 156 | }
|
216 | 157 |
|
@@ -557,53 +498,11 @@ nocachegetattr(HeapTuple tup,
|
557 | 498 | * Fix me when going to a machine with more than a four-byte
|
558 | 499 | * word!
|
559 | 500 | */
|
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); |
584 | 502 |
|
585 | 503 | att[j]->attcacheoff = off;
|
586 | 504 |
|
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); |
607 | 506 | }
|
608 | 507 |
|
609 | 508 | return (Datum) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
|
@@ -640,84 +539,20 @@ nocachegetattr(HeapTuple tup,
|
640 | 539 | off = att[i]->attcacheoff;
|
641 | 540 | else
|
642 | 541 | {
|
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 | + |
668 | 544 | if (usecache)
|
669 | 545 | att[i]->attcacheoff = off;
|
670 | 546 | }
|
671 | 547 |
|
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); |
695 | 549 |
|
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; |
719 | 552 | }
|
720 | 553 |
|
| 554 | + off = att_align(off, att[attnum]->attlen, att[attnum]->attalign); |
| 555 | + |
721 | 556 | return (Datum) fetchatt(&(att[attnum]), tp + off);
|
722 | 557 | }
|
723 | 558 | }
|
|
0 commit comments