diff --git a/Makefile b/Makefile index d4ab256..f9f8bed 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ # Students' Makefile for the Malloc Lab # CC = gcc -# CFLAGS = -Wall -O2 -m32 -CFLAGS = -Wall -O0 -m32 -g03 -pg +CFLAGS = -Wall -O2 -m32 +# CFLAGS = -Wall -O0 -m32 -g03 -pg OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o diff --git a/mm.c b/mm.c index 7c9b3b5..fe789a6 100644 --- a/mm.c +++ b/mm.c @@ -164,18 +164,17 @@ static void *place(void *ptr, size_t asize); @param[in] asize size class to look for in segregated list @result Size class (i.e. index of segregated list) */ -static int getSzClass(size_t asize); +static inline int getSzClass(size_t asize); //////////////////////////////////////////////////////////////////////////////// /////////////////////////////// HELPER FUNCTIONS /////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -static int getSzClass(size_t asize) { - for (size_t i = 0; i < LISTSIZE; ++i) { - if (asize == (1 << i)) { - return i; - } +static inline int getSzClass(size_t asize) { + int i; + for (i = 0; (i < LISTSIZE-1) && (asize > 1); ++i) { + asize >>= 1; } - return LISTSIZE-1; + return i; } static void *extend_heap(size_t size)