From d4d166835feb3cf33d812e209c61e5a9dfdc3f96 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 18 Oct 1994 16:58:24 +0000 Subject: [PATCH] * srec.c (tdata_type): Add field tail. (srec_mkobject): Initialize tail. (srec_set_section_contents): Sort S record list by address. --- bfd/ChangeLog | 6 ++++++ bfd/srec.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4c8eea2362..01e66039a7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +Tue Oct 18 12:56:43 1994 Ian Lance Taylor + + * srec.c (tdata_type): Add field tail. + (srec_mkobject): Initialize tail. + (srec_set_section_contents): Sort S record list by address. + Mon Oct 17 11:38:16 1994 Ian Lance Taylor * elfcode.h (elf_map_symbols): Sort the symbols into a new array, diff --git a/bfd/srec.c b/bfd/srec.c index 22f9eff5cb..f3612df10d 100644 --- a/bfd/srec.c +++ b/bfd/srec.c @@ -182,6 +182,7 @@ typedef struct srec_data_list_struct srec_data_list_type; typedef struct srec_data_struct { srec_data_list_type *head; + srec_data_list_type *tail; unsigned int type; int done_symbol_read; @@ -247,7 +248,7 @@ fillup_symbols (abfd, buf, len, val) p->value = val; p->flags = BSF_EXPORT | BSF_GLOBAL; p->section = bfd_abs_section_ptr; - p->udata = 0; + p->udata.p = NULL; } } /*ARGSUSED*/ @@ -327,7 +328,8 @@ srec_mkobject (abfd) } abfd->tdata.srec_data = tdata; tdata->type = 1; - tdata->head = (srec_data_list_type *) NULL; + tdata->head = NULL; + tdata->tail = NULL; } return true; @@ -599,10 +601,11 @@ srec_set_section_contents (abfd, section, location, offset, bytes_to_do) bfd_size_type bytes_to_do; { tdata_type *tdata = abfd->tdata.srec_data; - srec_data_list_type *entry = (srec_data_list_type *) - bfd_alloc (abfd, sizeof (srec_data_list_type)); + register srec_data_list_type *entry; - if (!entry) + entry = ((srec_data_list_type *) + bfd_alloc (abfd, sizeof (srec_data_list_type))); + if (entry == NULL) { bfd_set_error (bfd_error_no_memory); return false; @@ -612,7 +615,7 @@ srec_set_section_contents (abfd, section, location, offset, bytes_to_do) && (section->flags & SEC_LOAD)) { unsigned char *data = (unsigned char *) bfd_alloc (abfd, bytes_to_do); - if (!data) + if (data == NULL) { bfd_set_error (bfd_error_no_memory); return false; @@ -636,8 +639,29 @@ srec_set_section_contents (abfd, section, location, offset, bytes_to_do) entry->data = data; entry->where = section->lma + offset; entry->size = bytes_to_do; - entry->next = tdata->head; - tdata->head = entry; + + /* Sort the records by address. Optimize for the common case of + adding a record to the end of the list. */ + if (tdata->tail != NULL + && entry->where >= tdata->tail->where) + { + tdata->tail->next = entry; + entry->next = NULL; + tdata->tail = entry; + } + else + { + register srec_data_list_type **look; + + for (look = &tdata->head; + *look != NULL && (*look)->where < entry->where; + look = &(*look)->next) + ; + entry->next = *look; + *look = entry; + if (entry->next == NULL) + tdata->tail = entry; + } } return true; }