1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +00:00

Use inline for better performance

git-svn-id: svn://svn.cc65.org/cc65/trunk@726 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-05-16 09:24:42 +00:00
parent f78237a6a6
commit 87e9f7379b
5 changed files with 204 additions and 161 deletions

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -55,10 +55,10 @@ const char* MsgProgramAborted = "Program aborted: ";
static void DefaultCheckFailed (const char* msg, const char* cond,
int code, const char* file, unsigned line)
const char* file, unsigned line)
attribute ((noreturn));
void (*CheckFailed) (const char* Msg, const char* Cond, int Code,
void (*CheckFailed) (const char* Msg, const char* Cond,
const char* File, unsigned Line) attribute ((noreturn))
= DefaultCheckFailed;
/* Function pointer that is called from check if the condition code is true. */
@ -66,34 +66,16 @@ void (*CheckFailed) (const char* Msg, const char* Cond, int Code,
/*****************************************************************************/
/* Code */
/* Code */
/*****************************************************************************/
static void DefaultCheckFailed (const char* Msg, const char* Cond,
int Code, const char* File, unsigned Line)
const char* File, unsigned Line)
{
/* Log the error */
if (Code) {
AbEnd ("%s%s (= %d), file `%s', line %u", Msg, Cond, Code, File, Line);
} else {
AbEnd ("%s%s, file `%s', line %u", Msg, Cond, File, Line);
}
}
void Check (const char* Msg, const char* Cond, int Code,
const char* File, unsigned Line)
/* This function is called from all check macros (see below). It checks,
* wether the given Code is true (!= 0). If so, it calls the CheckFailed
* vector with the given strings. If not, it simply returns.
*/
{
if (Code != 0) {
CheckFailed (Msg, Cond, Code, File, Line);
}
/* Output a diagnostic and abort */
AbEnd ("%s%s, file `%s', line %u", Msg, Cond, File, Line);
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -56,7 +56,7 @@ extern const char* MsgProgramAborted; /* "Program aborted: " */
extern void (*CheckFailed) (const char* Msg, const char* Cond,
int Code, const char* File, unsigned Line)
const char* File, unsigned Line)
attribute ((noreturn));
/* Function pointer that is called from check if the condition code is true. */
@ -68,29 +68,20 @@ extern void (*CheckFailed) (const char* Msg, const char* Cond,
void Check (const char* Msg, const char* Cond, int Code,
const char* File, unsigned Line);
/* This function is called from all check macros (see below). It checks,
* wether the given Code is true (!= 0). If so, it calls the CheckFailed
* vector with the given strings. If not, it simply returns.
*/
#define FAIL(s) CheckFailed (MsgInternalError, s, 0, __FILE__, __LINE__)
#define FAIL(s) CheckFailed (MsgInternalError, s, __FILE__, __LINE__)
/* Fail macro. Is used if something evil happens, calls checkfailed directly. */
#define ABORT(s) CheckFailed (MsgProgramAborted, s, 0, __FILE__, __LINE__)
#define ABORT(s) CheckFailed (MsgProgramAborted, s, __FILE__, __LINE__)
/* Use this one instead of FAIL if there is no internal program error but an
* error condition that is caused by the user or operating system (FAIL and
* ABORT are essentially the same but the message differs).
*/
#define PRECONDITION(c) Check (MsgPrecondition, #c, !(c), __FILE__, __LINE__)
#define PRECONDITION(c) \
{ if (!(c)) CheckFailed (MsgPrecondition, #c, __FILE__, __LINE__); }
#define CHECK(c) Check (MsgCheckFailed, #c, !(c), __FILE__, __LINE__)
#define ZCHECK(c) Check (MsgCheckFailed, #c, c, __FILE__, __LINE__)
#define CHECK(c) \
{ if (!(c)) CheckFailed (MsgCheckFailed, #c, __FILE__, __LINE__); }

View File

@ -97,14 +97,6 @@ void FreeCollection (Collection* C)
unsigned CollCount (const Collection* C)
/* Return the number of items in the collection */
{
return C->Count;
}
void CollInsert (Collection* C, void* Item, unsigned Index)
/* Insert the data at the given position in the collection */
{
@ -138,77 +130,6 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
void CollAppend (Collection* C, void* Item)
/* Append an item to the end of the collection */
{
/* Insert the item at the end of the current list */
CollInsert (C, Item, C->Count);
}
void* CollAt (Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Check the index */
PRECONDITION (Index < C->Count);
/* Return the element */
return C->Items[Index];
}
const void* CollConstAt (const Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Check the index */
PRECONDITION (Index < C->Count);
/* Return the element */
return C->Items[Index];
}
void* CollLast (Collection* C)
/* Return the last item in a collection */
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
/* Return the element */
return C->Items[C->Count-1];
}
const void* CollConstLast (const Collection* C)
/* Return the last item in a collection */
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
/* Return the element */
return C->Items[C->Count-1];
}
void* CollPop (Collection* C)
/* Remove the last segment from the stack and return it. Calls FAIL if the
* collection is empty.
*/
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
/* Return the element */
return C->Items[--C->Count];
}
int CollIndex (Collection* C, const void* Item)
/* Return the index of the given item in the collection. Return -1 if the
* item was not found in the collection.
@ -261,31 +182,6 @@ void CollDeleteItem (Collection* C, const void* Item)
void CollDeleteAll (Collection* C)
/* Delete all items from the given collection. This will not free the items
* itself, it will only remove the pointers.
*/
{
/* This one is easy... */
C->Count = 0;
}
void CollReplace (Collection* C, void* Item, unsigned Index)
/* Replace the item at the given position. The old item will not be freed,
* just the pointer will et replaced.
*/
{
/* Check the index */
PRECONDITION (Index < C->Count);
/* Replace the item pointer */
C->Items[Index] = Item;
}
static void QuickSort (Collection* C, int Lo, int Hi,
int (*Compare) (void*, const void*, const void*),
void* Data)

View File

@ -38,7 +38,10 @@
/* common */
#include "attrib.h"
#include "cfeature.h"
#include "check.h"
@ -81,31 +84,122 @@ Collection* NewCollection (void);
void FreeCollection (Collection* C);
/* Free a collection */
unsigned CollCount (const Collection* C);
#if defined(HAVE_INLINE)
INLINE unsigned CollCount (const Collection* C)
/* Return the number of items in the collection */
{
return C->Count;
}
#else
# define CollCount(C) (C)->Count
#endif
void CollInsert (Collection* C, void* Item, unsigned Index);
/* Insert the data at the given position in the collection */
void CollAppend (Collection* C, void* Item);
#if defined(HAVE_INLINE)
INLINE void CollAppend (Collection* C, void* Item)
/* Append an item to the end of the collection */
{
/* Insert the item at the end of the current list */
CollInsert (C, Item, C->Count);
}
#else
# define CollAppend(C, Item) CollInsert (C, Item, (C)->Count)
#endif
void* CollAt (Collection* C, unsigned Index) attribute ((const));
#if defined(HAVE_INLINE)
INLINE void* CollAt (Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Check the index */
PRECONDITION (Index < C->Count);
const void* CollConstAt (const Collection* C, unsigned Index) attribute ((const));
/* Return the element */
return C->Items[Index];
}
#else
# define CollAt(C, Index) \
(PRECONDITION ((Index) < (C)->Count), \
(C)->Items[(Index)])
#endif
#if defined(HAVE_INLINE)
INLINE void* CollAtUnchecked (Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Return the element */
return C->Items[Index];
}
#else
# define CollAtUnchecked(C, Index) ((C)->Items[(Index)])
#endif
void* CollLast (Collection* C);
#if defined(HAVE_INLINE)
INLINE const void* CollConstAt (const Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Check the index */
PRECONDITION (Index < C->Count);
/* Return the element */
return C->Items[Index];
}
#else
# define CollConstAt(C, Index) \
(PRECONDITION ((Index) < (C)->Count), \
(C)->Items[(Index)])
#endif
#if defined(HAVE_INLINE)
INLINE void* CollLast (Collection* C)
/* Return the last item in a collection */
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
const void* CollConstLast (const Collection* C);
/* Return the element */
return C->Items[C->Count-1];
}
#else
# define CollLast(C) \
(PRECONDITION ((C)->Count > 0), \
(C)->Items[(C)->Count-1])
#endif
#if defined(HAVE_INLINE)
INLINE const void* CollConstLast (const Collection* C)
/* Return the last item in a collection */
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
void* CollPop (Collection* C);
/* Return the element */
return C->Items[C->Count-1];
}
#else
# define CollConstLast(C) \
(PRECONDITION ((C)->Count > 0), \
(C)->Items[(C)->Count-1])
#endif
#if defined(HAVE_INLINE)
INLINE void* CollPop (Collection* C)
/* Remove the last segment from the stack and return it. Calls FAIL if the
* collection is empty.
*/
{
/* We must have at least one entry */
PRECONDITION (C->Count > 0);
/* Return the element */
return C->Items[--C->Count];
}
#else
# define CollPop(C) \
(PRECONDITION ((C)->Count > 0), \
(C)->Items[--(C)->Count])
#endif
int CollIndex (Collection* C, const void* Item);
/* Return the index of the given item in the collection. Return -1 if the
@ -123,15 +217,36 @@ void CollDeleteItem (Collection* C, const void* Item);
* collection, otherwise FAIL will be called.
*/
void CollDeleteAll (Collection* C);
#if defined(HAVE_INLINE)
INLINE void CollDeleteAll (Collection* C)
/* Delete all items from the given collection. This will not free the items
* itself, it will only remove the pointers.
*/
{
/* This one is easy... */
C->Count = 0;
}
#else
# define CollDeleteAll(C) ((C)->Count = 0)
#endif
void CollReplace (Collection* C, void* Item, unsigned Index);
#if defined(HAVE_INLINE)
INLINE void CollReplace (Collection* C, void* Item, unsigned Index)
/* Replace the item at the given position. The old item will not be freed,
* just the pointer will et replaced.
*/
{
/* Check the index */
PRECONDITION (Index < C->Count);
/* Replace the item pointer */
C->Items[Index] = Item;
}
#else
# define CollReplace(C, Item, Index) \
(PRECONDITION ((Index) < (C)->Count), \
(C)->Items[(Index)] = (Item))
#endif
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),

59
src/common/inline.h Normal file
View File

@ -0,0 +1,59 @@
/*****************************************************************************/
/* */
/* cfeature.h */
/* */
/* Define compiler features */
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#ifndef CFEATURE_H
#define CFEATURE_H
/*****************************************************************************/
/* Defines */
/*****************************************************************************/
#if defined(__GNUC__)
# define HAVE_INLINE 1
# define INLINE static __inline__
#endif
/* End of cfeature.h */
#endif