git.iko.soy/typeable/html-parse
on master help sign in
Merge performance work
e478eeaBen Gamari
Text/HTML/Parser.hs+5−2
@@ -2,6 +2,8 @@
2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE LambdaCase #-}
4
4
5+{-# OPTIONS_GHC -O2 #-}
6+
5-- | This is a performance-oriented HTML tokenizer aim at web-crawling
7-- | This is a performance-oriented HTML tokenizer aim at web-crawling
6-- applications. It follows the HTML5 parsing specification quite closely,
8-- applications. It follows the HTML5 parsing specification quite closely,
7-- so it behaves reasonable well on ill-formed documents from the open Web.
9-- so it behaves reasonable well on ill-formed documents from the open Web.
@@ -176,9 +178,10 @@ attrName tag attrs = do
176 <|> (char '=' >> beforeAttrValue tag attrs name)
178 <|> (char '=' >> beforeAttrValue tag attrs name)
177 <|> try (do mc <- peekChar
179 <|> try (do mc <- peekChar
178 case mc of
180 case mc of
179− Just c | inClass "\x09\x0a\x0c />" c -> afterAttrName tag attrs name
181+ Just c | notNameChar c -> afterAttrName tag attrs name
180 _ -> empty)
182 _ -> empty)
181 -- <|> -- TODO: NULL
183 -- <|> -- TODO: NULL
184+ where notNameChar = isWhitespace `orC` isC '/' `orC` isC '>'
182
185
183-- | /§8.2.4.34/: After attribute name state
186-- | /§8.2.4.34/: After attribute name state
184afterAttrName :: TagName -> [Attr] -> AttrName -> Parser Token
187afterAttrName :: TagName -> [Attr] -> AttrName -> Parser Token
@@ -216,7 +219,7 @@ attrValueSQuoted tag attrs name = do
216-- | /§8.2.4.38/: Attribute value (unquoted) state
219-- | /§8.2.4.38/: Attribute value (unquoted) state
217attrValueUnquoted :: TagName -> [Attr] -> AttrName -> Parser Token
220attrValueUnquoted :: TagName -> [Attr] -> AttrName -> Parser Token
218attrValueUnquoted tag attrs name = do
221attrValueUnquoted tag attrs name = do
219− value <- takeTill (inClass "\x09\x0a\x0c >")
222+ value <- takeTill $ isWhitespace `orC` isC '>'
220 id $ (satisfy isWhitespace >> beforeAttrName tag attrs) -- unsure: don't emit?
223 id $ (satisfy isWhitespace >> beforeAttrName tag attrs) -- unsure: don't emit?
221 <|> (char '>' >> return (TagOpen tag (Attr name value : attrs)))
224 <|> (char '>' >> return (TagOpen tag (Attr name value : attrs)))
222 <|> (endOfInput >> return endOfFileToken)
225 <|> (endOfInput >> return endOfFileToken)
html-parse.cabal+1−1
@@ -16,7 +16,7 @@ description:
16 TagSelfClose "br" []]
16 TagSelfClose "br" []]
17 .
17 .
18 The package targets similar use-cases to the venerable @tagsoup@ library,
18 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
20 megabytes per second on modern hardware and typical web documents.
20 megabytes per second on modern hardware and typical web documents.
21 Here are some typical performance numbers taken from parsing a Wikipedia
21 Here are some typical performance numbers taken from parsing a Wikipedia
22 article of moderate length:
22 article of moderate length: