[GB.XML]
* OPT: Check if an element is self-closed only once when getting its string representation. git-svn-id: svn://localhost/gambas/trunk@5574 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
a300b16b36
commit
1df7e9baba
3 changed files with 15 additions and 7 deletions
|
@ -28,10 +28,10 @@
|
||||||
|
|
||||||
/*************************************** Element ***************************************/
|
/*************************************** Element ***************************************/
|
||||||
|
|
||||||
const char* Element::singleElements = "br\0hr\0area\0base\0br\0co\0command\0embed\0hr\0img\0input\0keygen\0link\0meta\0param\0source\0track\0wbr\0\0";
|
const char* Element::singleElements = "br\0img\0meta\0input\0area\0base\0co\0command\0embed\0hr\0keygen\0link\0param\0source\0track\0wbr\0\0";
|
||||||
#define LEN_SINGLEELEMENTS 89
|
#define LEN_SINGLEELEMENTS 84
|
||||||
|
|
||||||
Element::Element() : Node()
|
Element::Element() : Node(), single(undefined)
|
||||||
{
|
{
|
||||||
tagName = 0;
|
tagName = 0;
|
||||||
lenTagName = 0;
|
lenTagName = 0;
|
||||||
|
@ -44,7 +44,7 @@ Element::Element() : Node()
|
||||||
lenLocalName = 0;
|
lenLocalName = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Element::Element(const char *ntagName, size_t nlenTagName) : Node()
|
Element::Element(const char *ntagName, size_t nlenTagName) : Node(), single(undefined)
|
||||||
{
|
{
|
||||||
tagName = 0;
|
tagName = 0;
|
||||||
lenTagName = 0;
|
lenTagName = 0;
|
||||||
|
@ -101,8 +101,8 @@ void Element::setTagName(const char *ntagName, size_t nlenTagName)
|
||||||
lenTagName = nlenTagName;
|
lenTagName = nlenTagName;
|
||||||
tagName = (char*)realloc(tagName, sizeof(char) * lenTagName);
|
tagName = (char*)realloc(tagName, sizeof(char) * lenTagName);
|
||||||
memcpy(tagName, ntagName, lenTagName);
|
memcpy(tagName, ntagName, lenTagName);
|
||||||
|
single = undefined;
|
||||||
refreshPrefix();
|
refreshPrefix();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +162,7 @@ void Element::refreshPrefix()
|
||||||
|
|
||||||
bool Element::isSingle()
|
bool Element::isSingle()
|
||||||
{
|
{
|
||||||
|
if(single != undefined) return single;
|
||||||
const char *start = Element::singleElements;
|
const char *start = Element::singleElements;
|
||||||
char *end = (char*)memchr(start, 0, LEN_SINGLEELEMENTS);
|
char *end = (char*)memchr(start, 0, LEN_SINGLEELEMENTS);
|
||||||
unsigned char lenTag = end - start;
|
unsigned char lenTag = end - start;
|
||||||
|
@ -172,6 +173,7 @@ bool Element::isSingle()
|
||||||
{
|
{
|
||||||
if(!memcmp(tagName, start, lenTagName))
|
if(!memcmp(tagName, start, lenTagName))
|
||||||
{
|
{
|
||||||
|
single = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +182,8 @@ bool Element::isSingle()
|
||||||
end = (char*)memchr(start, 0, LEN_SINGLEELEMENTS - (singleElements - start));
|
end = (char*)memchr(start, 0, LEN_SINGLEELEMENTS - (singleElements - start));
|
||||||
lenTag = end - start;
|
lenTag = end - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
single = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
bool isSingle();
|
bool isSingle();
|
||||||
char *tagName;
|
char *tagName;
|
||||||
size_t lenTagName;
|
size_t lenTagName;
|
||||||
|
undefbool single;
|
||||||
|
|
||||||
void setPrefix(const char *nprefix, size_t nlenPrefix);
|
void setPrefix(const char *nprefix, size_t nlenPrefix);
|
||||||
char *prefix;
|
char *prefix;
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
|
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
|
||||||
|
typedef char undefbool;//A boolean with an "undefined" state
|
||||||
|
|
||||||
|
#define undefined 2//The "undefined" state of an undefbool
|
||||||
|
|
||||||
#define DELETE(_ob) if(_ob) {delete _ob; _ob = 0;}
|
#define DELETE(_ob) if(_ob) {delete _ob; _ob = 0;}
|
||||||
#define UNREF(_ob) if(_ob) GB.Unref(POINTER(&(_ob)))
|
#define UNREF(_ob) if(_ob) GB.Unref(POINTER(&(_ob)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue