Permalink
Browse files

regex =~ string is slightly faster than string =~ regex

  • Loading branch information...
archiloque committed Jul 9, 2011
1 parent 5dfc9ef commit c8d4bd4b84b27efe8fa689fdb5a41db9f95fb8fc
@@ -20,7 +20,7 @@ class Atom
elements :entry, :as => :entries, :class => AtomEntry
def self.able_to_parse?(xml) #:nodoc:
- xml =~ /\<feed[^\>]+xmlns=[\"|\'](http:\/\/www\.w3\.org\/2005\/Atom|http:\/\/purl\.org\/atom\/ns\#)[\"|\'][^\>]*\>/
+ /\<feed[^\>]+xmlns=[\"|\'](http:\/\/www\.w3\.org\/2005\/Atom|http:\/\/purl\.org\/atom\/ns\#)[\"|\'][^\>]*\>/ =~ xml
end
def url
@@ -1,5 +1,5 @@
module Feedzirra
-
+
module Parser
# == Summary
# Parser for dealing with Feedburner Atom feeds.
@@ -19,10 +19,10 @@ class AtomFeedBurner
elements :entry, :as => :entries, :class => AtomFeedBurnerEntry
def self.able_to_parse?(xml) #:nodoc:
- (xml =~ /Atom/ && xml =~ /feedburner/) || false
+ ((/Atom/ =~ xml) && (/feedburner/ =~ xml)) || false
end
end
end
-
+
end
@@ -1,5 +1,5 @@
module Feedzirra
-
+
module Parser
# iTunes is RSS 2.0 + some apple extensions
# Source: http://www.apple.com/itunes/whatson/podcasts/specs.html
@@ -40,11 +40,11 @@ class ITunesRSS
elements :item, :as => :entries, :class => ITunesRSSItem
def self.able_to_parse?(xml)
- xml =~ /xmlns:itunes=\"http:\/\/www.itunes.com\/dtds\/podcast-1.0.dtd\"/i
+ /xmlns:itunes=\"http:\/\/www.itunes.com\/dtds\/podcast-1.0.dtd\"/i =~ xml
end
end
-
+
end
-
+
end
@@ -1,5 +1,5 @@
module Feedzirra
-
+
module Parser
# == Summary
# Parser for dealing with RSS feeds.
@@ -20,10 +20,10 @@ class RSS
attr_accessor :feed_url
def self.able_to_parse?(xml) #:nodoc:
- xml =~ /\<rss|\<rdf/
+ /\<rss|\<rdf/ =~ xml
end
end
end
-
+
end

0 comments on commit c8d4bd4

Please sign in to comment.