shithub: mc

Download patch

ref: 0cae8df980a684eb9334e167765596b8e12b5728
parent: 097a3ddbf9b515200f31bae8343b696a58343fb3
author: Ori Bernstein <[email protected]>
date: Thu Dec 26 16:45:15 EST 2013

For the sake of efficiency, return -1 from charval.

--- a/libstd/intparse.myr
+++ b/libstd/intparse.myr
@@ -10,8 +10,8 @@
 	generic intparse	: (s : byte[:]	-> option(@a::(tcint,tcnum,tctest)))
 
 	/* FIXME: fix hidden exports */
-	generic charval : (c : char, base : int -> option(@a::(tcnum,tctest,tcint)))
-	generic doparse : (s : byte[:], isneg : bool, base : int -> option(@a::(tcnum,tctest,tcint)))
+	generic charval
+	generic doparse
 ;;
 
 generic intparse = {s
@@ -48,16 +48,16 @@
 
 generic doparse = {s, isneg, base
 	var c
-	var v
+	var v, cv
 	
 	v = 0
 	while s.len != 0
 		(c, s) = striter(s)
-		match charval(c, base)
-		| `Some cv:
+		cv = charval(c, base)
+		if cv > 0
 			v *= (base castto(@a::(tcint,tcnum,tctest)))
 			v += cv
-		| `None:
+		else
 			-> `None
 		;;
 	;;
@@ -81,7 +81,7 @@
 	;;
 
 	if v < 0 || v > (base castto(@a::(tcint,tcnum,tctest)))
-		-> `None
+		-> -1
 	;;
-	-> `Some v
+	-> v
 }