git.iko.soy/typeable/html-parse
on master help sign in
Merge performance work
commite478eead6a8a61f3902f4b9e0b281b511a0b8231 authorBen Gamari <ben@smart-cactus.org> dateFri 2 Feb 2018, 21:53 (9 years ago) parent442004406d3ab4
2 files changed+6−3
Text/HTML/Parser.hs+5−2 html-parse.cabal+1−1
Text/HTML/Parser.hs+5−2
@@ -2,6 +2,8 @@
22{-# LANGUAGE DeriveGeneric #-}
33{-# LANGUAGE LambdaCase #-}
44
5+{-# OPTIONS_GHC -O2 #-}
6+
57-- | This is a performance-oriented HTML tokenizer aim at web-crawling
68-- applications. It follows the HTML5 parsing specification quite closely,
79-- so it behaves reasonable well on ill-formed documents from the open Web.
@@ -176,9 +178,10 @@ attrName tag attrs = do
176178 <|> (char '=' >> beforeAttrValue tag attrs name)
177179 <|> try (do mc <- peekChar
178180 case mc of
179− Just c | inClass "\x09\x0a\x0c />" c -> afterAttrName tag attrs name
181+ Just c | notNameChar c -> afterAttrName tag attrs name
180182 _ -> empty)
181183 -- <|> -- TODO: NULL
184+ where notNameChar = isWhitespace `orC` isC '/' `orC` isC '>'
182185
183186-- | /§8.2.4.34/: After attribute name state
184187afterAttrName :: TagName -> [Attr] -> AttrName -> Parser Token
@@ -216,7 +219,7 @@ attrValueSQuoted tag attrs name = do
216219-- | /§8.2.4.38/: Attribute value (unquoted) state
217220attrValueUnquoted :: TagName -> [Attr] -> AttrName -> Parser Token
218221attrValueUnquoted tag attrs name = do
219− value <- takeTill (inClass "\x09\x0a\x0c >")
222+ value <- takeTill $ isWhitespace `orC` isC '>'
220223 id $ (satisfy isWhitespace >> beforeAttrName tag attrs) -- unsure: don't emit?
221224 <|> (char '>' >> return (TagOpen tag (Attr name value : attrs)))
222225 <|> (endOfInput >> return endOfFileToken)
html-parse.cabal+1−1
@@ -16,7 +16,7 @@ description:
1616 TagSelfClose "br" []]
1717 .
1818 The package targets similar use-cases to the venerable @tagsoup@ library,
19− but is significantly more efficient, achieving parsing speeds of over 50
19+ but is significantly more efficient, achieving parsing speeds of over 80
2020 megabytes per second on modern hardware and typical web documents.
2121 Here are some typical performance numbers taken from parsing a Wikipedia
2222 article of moderate length: