Changeset 01e48c1 in mainline


Ignore:
Timestamp:
2005-09-15T21:02:27Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a50f59
Parents:
d6dcdd2e
Message:

Optimize sorting functions so that malloc() and free() is called only for e_size > EBUFSIZE.
Smaller buffers are allocated directly on the stack.

Some copyright holder fixes on some files written by Ondrej Palkovsky.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/include/mm/frame.h

    rd6dcdd2e r01e48c1  
    11/*
    2  * Copyright (C) 2005 Martin Decky
     2 * Copyright (C) 2005 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
  • arch/amd64/include/mm/page.h

    rd6dcdd2e r01e48c1  
    11/*
    2  * Copyright (C) 2005 Martin Decky
     2 * Copyright (C) 2005 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
  • arch/amd64/include/mm/vm.h

    rd6dcdd2e r01e48c1  
    11/*
    2  * Copyright (C) 2005 Martin Decky
     2 * Copyright (C) 2005 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
  • arch/ia32/src/acpi/madt.c

    rd6dcdd2e r01e48c1  
    113113int madt_cmp(void * a, void * b)
    114114{
    115     return
    116         (((struct madt_apic_header *) a)->type > ((struct madt_apic_header *) b)->type) ?
    117         1 :
    118         ((((struct madt_apic_header *) a)->type < ((struct madt_apic_header *) b)->type) ? -1 : 0);
     115        return
     116                (((struct madt_apic_header *) a)->type > ((struct madt_apic_header *) b)->type) ?
     117                1 :
     118                ((((struct madt_apic_header *) a)->type < ((struct madt_apic_header *) b)->type) ? -1 : 0);
    119119}
    120120       
    121121void acpi_madt_parse(void)
    122122{
    123 
    124 
    125123        struct madt_apic_header *end = (struct madt_apic_header *) (((__u8 *) acpi_madt) + acpi_madt->header.length);
    126124        struct madt_apic_header *h;
  • src/lib/sort.c

    rd6dcdd2e r01e48c1  
    3232#include <panic.h>
    3333
     34#define EBUFSIZE        32
     35
    3436static void _qsort(void * data, count_t n, size_t e_size, int (* cmp) (void * a, void * b), void * pivot, void * tmp);
    3537
     
    3840 */
    3941void qsort(void * data, count_t n, size_t e_size, int (* cmp) (void * a, void * b)) {
    40         void * tmp = (void *) malloc(e_size);
    41         void * pivot = (void *) malloc(e_size);
     42        __u8 buf_tmp[EBUFSIZE];
     43        __u8 buf_pivot[EBUFSIZE];
     44        void * tmp = buf_tmp;
     45        void * pivot = buf_pivot;
     46
     47        if (e_size > EBUFSIZE) {
     48                pivot = (void *) malloc(e_size);
     49                tmp = (void *) malloc(e_size);
    4250       
    43         if (!tmp || !pivot) {
    44                 panic("Cannot allocate memory\n");
     51                if (!tmp || !pivot) {
     52                        panic("Cannot allocate memory\n");
     53                }
    4554        }
    4655
    4756        _qsort(data, n, e_size, cmp, pivot, tmp);
    4857       
    49         free(tmp);
    50         free(pivot);
     58        if (e_size > EBUFSIZE) {
     59                free(tmp);
     60                free(pivot);
     61        }
    5162}
    5263
    5364
    5465void bubblesort(void * data, count_t n, size_t e_size, int (* cmp) (void * a, void * b)) {
     66        __u8 buf_slot[EBUFSIZE];
    5567        bool done = false;
    5668        void * p;
    57         void * slot = (void *) malloc(e_size);
     69        void * slot = buf_slot;
     70       
     71        if (e_size > EBUFSIZE) {
     72                slot = (void *) malloc(e_size);
     73               
     74                if (!slot) {
     75                        panic("Cannot allocate memory\n");
     76                }
     77        }
    5878
    5979        while (!done) {
     
    6989        }
    7090       
    71         free(slot);
     91        if (e_size > EBUFSIZE) {       
     92                free(slot);
     93        }
    7294}
    7395
Note: See TracChangeset for help on using the changeset viewer.