1. Shlomi Fish
  2. Fiction-XML

Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed 243a9fd

Convert to a hash lookup.

  • Participants
  • Parent commits 99ad6be
  • Branches default

Comments (0)

Files changed (1)

File perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/FromProto/Parser/XmlIterator.pm

View file
 # Whether we are inside a paragraph or not.
 has "_in_para" => (isa => "Bool", is => "rw", default => 0,);
 
+has '_tag_names_to_be_handled' =>
+(
+    is => 'ro',
+    isa => 'HashRef[Bool]',
+    lazy => 1,
+    builder => '_build_tag_names_to_be_handled',
+);
+
+sub _build_tag_names_to_be_handled
+{
+    my $self = shift;
+
+    return { map { $_ => 1 } @{$self->_list_valid_tag_events} };
+}
+
 sub _get_id_regex
 {
     return qr{[a-zA-Z_\-]+};
 {
     my ($self, $event) = @_;
 
-    foreach my $tag_name (@{$self->_list_valid_tag_events()})
+    if ($event->tag && exists($self->_tag_names_to_be_handled->{$event->tag}))
     {
-        if ($event->is_tag_of_name($tag_name))
-        {
-            return $self->_handle_specific_tag_event($event);
-        }
+        return $self->_handle_specific_tag_event($event);
     }
-
-    return;
+    else
+    {
+        return;
+    }
 }
 
 sub _handle_para_event