- return;
- }
- if (ao_lisp_chunk[i].old_addr > addr) {
- int end = min(AO_LISP_NCHUNK, chunk_busy + 1);
- memmove(&ao_lisp_chunk[i+1],
- &ao_lisp_chunk[i],
- (end - (i+1)) * sizeof (struct ao_lisp_chunk));
- break;
- }
- }
- if (i < AO_LISP_NCHUNK) {
- ao_lisp_chunk[i].old_addr = addr;
- ao_lisp_chunk[i].size = size;
- if (chunk_busy < AO_LISP_NCHUNK)
- chunk_busy++;
- else
- chunk_high = ao_lisp_chunk[AO_LISP_NCHUNK-1].old_addr +
- ao_lisp_chunk[AO_LISP_NCHUNK-1].size;
- }
+
+ /* Shuffle existing entries right */
+ int end = min(AO_LISP_NCHUNK, chunk_last + 1);
+
+ memmove(&ao_lisp_chunk[l+1],
+ &ao_lisp_chunk[l],
+ (end - (l+1)) * sizeof (struct ao_lisp_chunk));
+
+ /* Add new entry */
+ ao_lisp_chunk[l].old_offset = offset;
+ ao_lisp_chunk[l].size = size;
+
+ /* Increment the number of elements up to the size of the array */
+ if (chunk_last < AO_LISP_NCHUNK)
+ chunk_last++;
+
+ /* Set the top address if the array is full */
+ if (chunk_last == AO_LISP_NCHUNK)
+ chunk_high = ao_lisp_chunk[AO_LISP_NCHUNK-1].old_offset +
+ ao_lisp_chunk[AO_LISP_NCHUNK-1].size;