forked from AuroraMiddleware/gtk
builderparser: Save tag type instead of tag name
So we can save a few string comparisons
This commit is contained in:
parent
e3a3a66370
commit
938598032c
@ -34,6 +34,17 @@
|
|||||||
static void free_property_info (PropertyInfo *info);
|
static void free_property_info (PropertyInfo *info);
|
||||||
static void free_object_info (ObjectInfo *info);
|
static void free_object_info (ObjectInfo *info);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TAG_PROPERTY,
|
||||||
|
TAG_MENU,
|
||||||
|
TAG_REQUIRES,
|
||||||
|
TAG_OBJECT,
|
||||||
|
TAG_CHILD,
|
||||||
|
TAG_SIGNAL,
|
||||||
|
TAG_INTERFACE,
|
||||||
|
TAG_TEMPLATE,
|
||||||
|
};
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
state_push (ParserData *data, gpointer info)
|
state_push (ParserData *data, gpointer info)
|
||||||
{
|
{
|
||||||
@ -214,7 +225,7 @@ parse_requires (ParserData *data,
|
|||||||
req_info->major = version_major;
|
req_info->major = version_major;
|
||||||
req_info->minor = version_minor;
|
req_info->minor = version_minor;
|
||||||
state_push (data, req_info);
|
state_push (data, req_info);
|
||||||
req_info->tag.name = element_name;
|
req_info->tag.tag_type = TAG_REQUIRES;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -251,7 +262,7 @@ parse_object (GMarkupParseContext *context,
|
|||||||
gint line;
|
gint line;
|
||||||
|
|
||||||
child_info = state_peek_info (data, ChildInfo);
|
child_info = state_peek_info (data, ChildInfo);
|
||||||
if (child_info && strcmp (child_info->tag.name, "object") == 0)
|
if (child_info && child_info->tag.tag_type == TAG_OBJECT)
|
||||||
{
|
{
|
||||||
error_invalid_tag (data, element_name, NULL, error);
|
error_invalid_tag (data, element_name, NULL, error);
|
||||||
return;
|
return;
|
||||||
@ -332,7 +343,7 @@ parse_object (GMarkupParseContext *context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
object_info = g_slice_new0 (ObjectInfo);
|
object_info = g_slice_new0 (ObjectInfo);
|
||||||
object_info->tag.name = element_name;
|
object_info->tag.tag_type = TAG_OBJECT;
|
||||||
object_info->type = object_type;
|
object_info->type = object_type;
|
||||||
object_info->oclass = g_type_class_ref (object_type);
|
object_info->oclass = g_type_class_ref (object_type);
|
||||||
object_info->id = (internal_id) ? internal_id : g_strdup (object_id);
|
object_info->id = (internal_id) ? internal_id : g_strdup (object_id);
|
||||||
@ -437,7 +448,7 @@ parse_template (GMarkupParseContext *context,
|
|||||||
++data->cur_object_level;
|
++data->cur_object_level;
|
||||||
|
|
||||||
object_info = g_slice_new0 (ObjectInfo);
|
object_info = g_slice_new0 (ObjectInfo);
|
||||||
object_info->tag.name = element_name;
|
object_info->tag.tag_type = TAG_TEMPLATE;
|
||||||
object_info->type = parsed_type;
|
object_info->type = parsed_type;
|
||||||
object_info->oclass = g_type_class_ref (parsed_type);
|
object_info->oclass = g_type_class_ref (parsed_type);
|
||||||
object_info->id = g_strdup (object_class);
|
object_info->id = g_strdup (object_class);
|
||||||
@ -496,8 +507,8 @@ parse_child (ParserData *data,
|
|||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
!(strcmp (object_info->tag.name, "object") == 0 ||
|
!(object_info->tag.tag_type == TAG_OBJECT ||
|
||||||
strcmp (object_info->tag.name, "template") == 0))
|
object_info->tag.tag_type == TAG_TEMPLATE))
|
||||||
{
|
{
|
||||||
error_invalid_tag (data, element_name, NULL, error);
|
error_invalid_tag (data, element_name, NULL, error);
|
||||||
return;
|
return;
|
||||||
@ -513,7 +524,7 @@ parse_child (ParserData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
child_info = g_slice_new0 (ChildInfo);
|
child_info = g_slice_new0 (ChildInfo);
|
||||||
child_info->tag.name = element_name;
|
child_info->tag.tag_type = TAG_CHILD;
|
||||||
child_info->type = g_strdup (type);
|
child_info->type = g_strdup (type);
|
||||||
child_info->internal_child = g_strdup (internal_child);
|
child_info->internal_child = g_strdup (internal_child);
|
||||||
child_info->parent = (CommonInfo*)object_info;
|
child_info->parent = (CommonInfo*)object_info;
|
||||||
@ -551,8 +562,8 @@ parse_property (ParserData *data,
|
|||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
!(strcmp (object_info->tag.name, "object") == 0 ||
|
!(object_info->tag.tag_type == TAG_OBJECT ||
|
||||||
strcmp (object_info->tag.name, "template") == 0))
|
object_info->tag.tag_type == TAG_TEMPLATE))
|
||||||
{
|
{
|
||||||
error_invalid_tag (data, element_name, NULL, error);
|
error_invalid_tag (data, element_name, NULL, error);
|
||||||
return;
|
return;
|
||||||
@ -620,7 +631,7 @@ parse_property (ParserData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
info = g_slice_new (PropertyInfo);
|
info = g_slice_new (PropertyInfo);
|
||||||
info->tag.name = element_name;
|
info->tag.tag_type = TAG_PROPERTY;
|
||||||
info->pspec = pspec;
|
info->pspec = pspec;
|
||||||
info->text = g_string_new ("");
|
info->text = g_string_new ("");
|
||||||
info->translatable = translatable;
|
info->translatable = translatable;
|
||||||
@ -659,8 +670,8 @@ parse_signal (ParserData *data,
|
|||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
!(strcmp (object_info->tag.name, "object") == 0 ||
|
!(object_info->tag.tag_type == TAG_OBJECT||
|
||||||
strcmp (object_info->tag.name, "template") == 0))
|
object_info->tag.tag_type == TAG_TEMPLATE))
|
||||||
{
|
{
|
||||||
error_invalid_tag (data, element_name, NULL, error);
|
error_invalid_tag (data, element_name, NULL, error);
|
||||||
return;
|
return;
|
||||||
@ -710,7 +721,7 @@ parse_signal (ParserData *data,
|
|||||||
info->connect_object_name = g_strdup (object);
|
info->connect_object_name = g_strdup (object);
|
||||||
state_push (data, info);
|
state_push (data, info);
|
||||||
|
|
||||||
info->tag.name = element_name;
|
info->tag.tag_type = TAG_SIGNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called by GtkBuilder */
|
/* Called by GtkBuilder */
|
||||||
@ -868,8 +879,8 @@ parse_custom (GMarkupParseContext *context,
|
|||||||
if (!parent_info)
|
if (!parent_info)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (strcmp (parent_info->tag.name, "object") == 0 ||
|
if (parent_info->tag.tag_type == TAG_OBJECT ||
|
||||||
strcmp (parent_info->tag.name, "template") == 0)
|
parent_info->tag.tag_type == TAG_TEMPLATE)
|
||||||
{
|
{
|
||||||
ObjectInfo* object_info = (ObjectInfo*)parent_info;
|
ObjectInfo* object_info = (ObjectInfo*)parent_info;
|
||||||
if (!object_info->object)
|
if (!object_info->object)
|
||||||
@ -885,7 +896,7 @@ parse_custom (GMarkupParseContext *context,
|
|||||||
object = object_info->object;
|
object = object_info->object;
|
||||||
child = NULL;
|
child = NULL;
|
||||||
}
|
}
|
||||||
else if (strcmp (parent_info->tag.name, "child") == 0)
|
else if (parent_info->tag.tag_type == TAG_CHILD)
|
||||||
{
|
{
|
||||||
ChildInfo* child_info = (ChildInfo*)parent_info;
|
ChildInfo* child_info = (ChildInfo*)parent_info;
|
||||||
|
|
||||||
@ -1096,8 +1107,8 @@ end_element (GMarkupParseContext *context,
|
|||||||
g_assert (info != NULL);
|
g_assert (info != NULL);
|
||||||
|
|
||||||
/* Normal properties */
|
/* Normal properties */
|
||||||
if (strcmp (info->tag.name, "object") == 0 ||
|
if (info->tag.tag_type == TAG_OBJECT ||
|
||||||
strcmp (info->tag.name, "template") == 0)
|
info->tag.tag_type == TAG_TEMPLATE)
|
||||||
{
|
{
|
||||||
ObjectInfo *object_info = (ObjectInfo*)info;
|
ObjectInfo *object_info = (ObjectInfo*)info;
|
||||||
|
|
||||||
@ -1186,21 +1197,30 @@ text (GMarkupParseContext *context,
|
|||||||
static void
|
static void
|
||||||
free_info (CommonInfo *info)
|
free_info (CommonInfo *info)
|
||||||
{
|
{
|
||||||
if (strcmp (info->tag.name, "object") == 0 ||
|
switch (info->tag.tag_type)
|
||||||
strcmp (info->tag.name, "template") == 0)
|
{
|
||||||
free_object_info ((ObjectInfo *)info);
|
case TAG_OBJECT:
|
||||||
else if (strcmp (info->tag.name, "child") == 0)
|
case TAG_TEMPLATE:
|
||||||
free_child_info ((ChildInfo *)info);
|
free_object_info ((ObjectInfo *)info);
|
||||||
else if (strcmp (info->tag.name, "property") == 0)
|
break;
|
||||||
free_property_info ((PropertyInfo *)info);
|
case TAG_CHILD:
|
||||||
else if (strcmp (info->tag.name, "signal") == 0)
|
free_child_info ((ChildInfo *)info);
|
||||||
_free_signal_info ((SignalInfo *)info, NULL);
|
break;
|
||||||
else if (strcmp (info->tag.name, "requires") == 0)
|
case TAG_PROPERTY:
|
||||||
free_requires_info ((RequiresInfo *)info, NULL);
|
free_property_info ((PropertyInfo *)info);
|
||||||
else if (strcmp (info->tag.name, "menu") == 0)
|
break;
|
||||||
free_menu_info ((MenuInfo *)info);
|
case TAG_SIGNAL:
|
||||||
else
|
_free_signal_info ((SignalInfo *)info, NULL);
|
||||||
g_assert_not_reached ();
|
break;
|
||||||
|
case TAG_REQUIRES:
|
||||||
|
free_requires_info ((RequiresInfo *)info, NULL);
|
||||||
|
break;
|
||||||
|
case TAG_MENU:
|
||||||
|
free_menu_info ((MenuInfo *)info);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GMarkupParser parser = {
|
static const GMarkupParser parser = {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "gtkbuilder.h"
|
#include "gtkbuilder.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const gchar *name;
|
guint tag_type;
|
||||||
} TagInfo;
|
} TagInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user