Skip to content

Commit ed8b5ae

Browse files
committed
Merge pull request tototoshi#35 from xuwei-k/use-switch
optimize CSVParser#parse
2 parents 0101148 + 99ebb20 commit ed8b5ae

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/main/scala/com/github/tototoshi/csv/CSVParser.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
*/
1616
package com.github.tototoshi.csv
1717

18+
import scala.annotation.switch
19+
1820
object CSVParser {
1921

20-
abstract sealed trait State
21-
case object Start extends State
22-
case object Field extends State
23-
case object Delimiter extends State
24-
case object End extends State
25-
case object QuoteStart extends State
26-
case object QuoteEnd extends State
27-
case object QuotedField extends State
22+
private type State = Int
23+
private final val Start = 0
24+
private final val Field = 1
25+
private final val Delimiter = 2
26+
private final val End = 3
27+
private final val QuoteStart = 4
28+
private final val QuoteEnd = 5
29+
private final val QuotedField = 6
2830

2931
/**
3032
* {{{
@@ -45,7 +47,7 @@ object CSVParser {
4547

4648
while (state != End && pos < buflen) {
4749
val c = buf(pos)
48-
state match {
50+
(state: @switch) match {
4951
case Start => {
5052
c match {
5153
case `quoteChar` => {
@@ -244,7 +246,7 @@ object CSVParser {
244246
}
245247
}
246248
}
247-
state match {
249+
(state: @switch) match {
248250
case Delimiter => {
249251
fields :+= ""
250252
Some(fields.toList)

0 commit comments

Comments
 (0)