Removed the flags and optimized the Attr structure.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5596 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -53,33 +53,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int IsNumber (const char* Value)
|
|
||||||
/* Check if Value is an integer number */
|
|
||||||
{
|
|
||||||
if (*Value == '-' || *Value == '+') {
|
|
||||||
++Value;
|
|
||||||
}
|
|
||||||
while (IsDigit (*Value)) {
|
|
||||||
++Value;
|
|
||||||
}
|
|
||||||
return (*Value == '\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Attr* NewAttr (const char* Name, const char* Value)
|
Attr* NewAttr (const char* Name, const char* Value)
|
||||||
/* Create a new attribute */
|
/* Create a new attribute */
|
||||||
{
|
{
|
||||||
/* Determine the length of Value */
|
/* Determine the string lengths */
|
||||||
unsigned Len = strlen (Value);
|
unsigned NameLen = strlen (Name);
|
||||||
|
unsigned ValueLen = strlen (Value);
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
Attr* A = xmalloc (sizeof (Attr) + Len);
|
Attr* A = xmalloc (sizeof (Attr) + ValueLen + NameLen + 1);
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
A->Flags = IsNumber (Value)? afInt : afNone;
|
A->Name = A->Value + ValueLen + 1;
|
||||||
A->Name = xstrdup (Name);
|
memcpy (A->Value, Value, ValueLen + 1);
|
||||||
memcpy (A->Value, Value, Len + 1);
|
memcpy (A->Name, Name, NameLen + 1);
|
||||||
|
|
||||||
/* Return the new struct */
|
/* Return the new struct */
|
||||||
return A;
|
return A;
|
||||||
@@ -90,11 +77,7 @@ Attr* NewAttr (const char* Name, const char* Value)
|
|||||||
void FreeAttr (Attr* A)
|
void FreeAttr (Attr* A)
|
||||||
/* Free an attribute structure */
|
/* Free an attribute structure */
|
||||||
{
|
{
|
||||||
/* Allow NULL pointers */
|
xfree (A);
|
||||||
if (A) {
|
|
||||||
xfree (A->Name);
|
|
||||||
xfree (A);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -309,7 +292,7 @@ Collection* ParseAttrList (const char* List, const char** NameList, unsigned Nam
|
|||||||
|
|
||||||
|
|
||||||
void FreeAttrList (Collection* C)
|
void FreeAttrList (Collection* C)
|
||||||
/* Free a list of attributes */
|
/* Free a list of attributes */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
|
||||||
|
|||||||
@@ -49,19 +49,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Attribute flags */
|
/* Attribute structure */
|
||||||
enum AttrFlags {
|
|
||||||
afNone,
|
|
||||||
afInt, /* Integer number */
|
|
||||||
};
|
|
||||||
typedef enum AttrFlags AttrFlags;
|
|
||||||
|
|
||||||
/* */
|
|
||||||
typedef struct Attr Attr;
|
typedef struct Attr Attr;
|
||||||
struct Attr {
|
struct Attr {
|
||||||
AttrFlags Flags; /* Attribute flags */
|
char* Name; /* Attribute name - points into Value */
|
||||||
char* Name; /* Attribute name */
|
char Value[1]; /* Attribute value followed by Name */
|
||||||
char Value[1]; /* Attribute value */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user