Created
July 13, 2014 01:17
-
-
Save rubyu/871c22b13cf7060a2175 to your computer and use it in GitHub Desktop.
ScalaのRegexParsersで書いたパーサのチューニング方法 #2 ref: http://qiita.com/rubyu/items/de843a441859cf81af48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(access count: A,31) | |
(access count: B,40) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//適当なCSVパーサの定義 | |
//lazy val field = "[a-z]+".r | |
lazy val A = field ~ ( rep( "," ~ field ) ).? | |
lazy val B = ( rep( field ~ "," ) ).? ~ field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 0 | |
class DebugCharSequence(seq: CharSequence) extends java.lang.CharSequence { | |
def charAt(n: Int) = { count += 1; seq.charAt(n) } | |
def subSequence(s: Int, e: Int) = new DebugCharSequence(seq.subSequence(s, e)) | |
def length = seq.length | |
override def toString = seq.toString | |
} | |
val dseq = new DebugCharSequence("a,b,c") | |
parser.parse(parser.A, dseq) | |
println("access count: A", count) | |
count = 0 | |
parser.parse(parser.B, dseq) | |
println("access count: B", count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment