Skip to content

Commit 3b905bc

Browse files
committed
Swap tid and pos in bam1_core_t to eliminate struct holes
Removes four bytes of padding between tid and pos, and four bytes between mtid and mpos.
1 parent c0ddabb commit 3b905bc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

htslib/sam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ extern const int8_t bam_cigar_table[256];
200200
@field mpos 0-based leftmost coordinate of next read in template
201201
*/
202202
typedef struct {
203-
int32_t tid;
204203
hts_pos_t pos;
204+
int32_t tid;
205205
uint16_t bin; // NB: invalid on 64-bit pos
206206
uint8_t qual;
207207
uint8_t l_extranul;

test/sam.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ static void samrecord_layout(void)
985985
size_t bam1_t_size, bam1_t_size2;
986986

987987
assert(sizeof(hts_pos_t) == 8 || sizeof(hts_pos_t) == 4);
988-
int core_size = sizeof(hts_pos_t) == 8 ? 56 : 36;
988+
int core_size = sizeof(hts_pos_t) == 8 ? 48 : 36;
989989

990990
bam1_t_size = core_size + sizeof (int) + 4 + sizeof (char *);
991991
#ifndef BAM_NO_ID
@@ -994,7 +994,8 @@ static void samrecord_layout(void)
994994
bam1_t_size2 = bam1_t_size + 4; // Account for padding on some platforms
995995

996996
if (sizeof (bam1_core_t) != core_size)
997-
fail("sizeof bam1_core_t is %zu, expected 56", sizeof (bam1_core_t));
997+
fail("sizeof bam1_core_t is %zu, expected %d",
998+
sizeof (bam1_core_t), core_size);
998999

9991000
if (sizeof (bam1_t) != bam1_t_size && sizeof (bam1_t) != bam1_t_size2)
10001001
fail("sizeof bam1_t is %zu, expected either %zu or %zu",

0 commit comments

Comments
 (0)