[m-rev.] for review: more switches in lexer.m
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon Jun 2 12:29:02 AEST 2008
For review by anyone.
Zoltan.
library/lexer.m:
Convert a couple more if-then-else chains into switches. This one
gains 0.2% in speed.
cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/lexer.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/lexer.m,v
retrieving revision 1.58
diff -u -b -r1.58 lexer.m
--- library/lexer.m 20 May 2008 00:52:31 -0000 1.58
+++ library/lexer.m 31 May 2008 08:10:26 -0000
@@ -210,16 +210,39 @@
token_list::out, io::di, io::uo) is det.
get_token_list_2(Stream, Token0, Context0, Tokens, !IO) :-
- ( Token0 = eof ->
+ (
+ Token0 = eof,
Tokens = token_nil
- ; ( Token0 = end ; Token0 = error(_) ; Token0 = io_error(_) ) ->
+ ;
+ ( Token0 = end
+ ; Token0 = error(_)
+ ; Token0 = io_error(_)
+ ),
Tokens = token_cons(Token0, Context0, token_nil)
- ; Token0 = integer_dot(Int) ->
+ ;
+ Token0 = integer_dot(Int),
get_context(Stream, Context1, !IO),
get_dot(Stream, Token1, !IO),
get_token_list_2(Stream, Token1, Context1, Tokens1, !IO),
Tokens = token_cons(integer(Int), Context0, Tokens1)
;
+ ( Token0 = float(_)
+ ; Token0 = string(_)
+ ; Token0 = variable(_)
+ ; Token0 = integer(_)
+ ; Token0 = implementation_defined(_)
+ ; Token0 = junk(_)
+ ; Token0 = name(_)
+ ; Token0 = open
+ ; Token0 = open_ct
+ ; Token0 = close
+ ; Token0 = open_list
+ ; Token0 = close_list
+ ; Token0 = open_curly
+ ; Token0 = close_curly
+ ; Token0 = comma
+ ; Token0 = ht_sep
+ ),
get_token(Stream, Token1, Context1, !IO),
get_token_list_2(Stream, Token1, Context1, Tokens1, !IO),
Tokens = token_cons(Token0, Context0, Tokens1)
@@ -231,11 +254,34 @@
string_get_token_list_max(String, Len, Tokens, !Posn) :-
string_get_token(String, Len, Token, Context, !Posn),
- ( Token = eof ->
+ (
+ Token = eof,
Tokens = token_nil
- ; ( Token = end ; Token = error(_) ; Token = io_error(_) ) ->
+ ;
+ ( Token = end
+ ; Token = error(_)
+ ; Token = io_error(_)
+ ),
Tokens = token_cons(Token, Context, token_nil)
;
+ ( Token = float(_)
+ ; Token = string(_)
+ ; Token = variable(_)
+ ; Token = integer(_)
+ ; Token = integer_dot(_)
+ ; Token = implementation_defined(_)
+ ; Token = junk(_)
+ ; Token = name(_)
+ ; Token = open
+ ; Token = open_ct
+ ; Token = close
+ ; Token = open_list
+ ; Token = close_list
+ ; Token = open_curly
+ ; Token = close_curly
+ ; Token = comma
+ ; Token = ht_sep
+ ),
Tokens = token_cons(Token, Context, Tokens1),
string_get_token_list_max(String, Len, Tokens1, !Posn)
).
@@ -1263,11 +1309,11 @@
encode_unicode_char_as_utf8(UnicodeCharCode, UTF8Chars) :-
allowed_unicode_char_code(UnicodeCharCode),
- %
+
% Refer to table 3-5 of the Unicode 4.0.0 standard (available from
% www.unicode.org) for documentation on the bit distribution patterns used
% below.
- %
+
( if UnicodeCharCode =< 0x00007F then
UTF8Chars = [char.det_from_int(UnicodeCharCode)]
else if UnicodeCharCode =< 0x0007FF then
@@ -1303,11 +1349,11 @@
%
encode_unicode_char_as_utf16(UnicodeCharCode, UTF16Chars) :-
allowed_unicode_char_code(UnicodeCharCode),
- %
+
% If the code point is less than or equal to 0xFFFF
% then the UTF-16 encoding is simply the code point value,
% otherwise we construct a surrogate pair.
- %
+
( if UnicodeCharCode =< 0xFFFF then
char.det_from_int(UnicodeCharCode, Char),
UTF16Chars = [Char]
@@ -1351,8 +1397,8 @@
backend_unicode_encoding = Encoding :-
Int = backend_unicode_encoding_int,
- ( unicode_encoding_int_to_encoding(Int, Encoding0) ->
- Encoding = Encoding0
+ ( unicode_encoding_int_to_encoding(Int, EncodingPrime) ->
+ Encoding = EncodingPrime
;
error("backend_unicode_encoding: unexpected Unicode encoding code")
).
@@ -2429,13 +2475,13 @@
string_get_context(Posn0, Context, !Posn)
).
-:- pred get_float_exponent_2(io.input_stream::in, list(char)::in, token::out,
- io::di, io::uo) is det.
-
% We've read past the E signalling the start of the exponent -
% make sure that there's at least one digit following,
% and then get the remaining digits.
%
+:- pred get_float_exponent_2(io.input_stream::in, list(char)::in, token::out,
+ io::di, io::uo) is det.
+
get_float_exponent_2(Stream, Chars, Token, !IO) :-
io.read_char_unboxed(Stream, Result, Char, !IO),
(
@@ -2454,13 +2500,13 @@
)
).
-:- pred string_get_float_exponent_2(string::in, int::in, posn::in,
- token::out, string_token_context::out, posn::in, posn::out) is det.
-
% We've read past the E signalling the start of the exponent -
% make sure that there's at least one digit following,
% and then get the remaining digits.
%
+:- pred string_get_float_exponent_2(string::in, int::in, posn::in,
+ token::out, string_token_context::out, posn::in, posn::out) is det.
+
string_get_float_exponent_2(String, Len, Posn0, Token, Context, !Posn) :-
( string_read_char(String, Len, Char, !Posn) ->
( char.is_digit(Char) ->
@@ -2476,12 +2522,12 @@
string_get_context(Posn0, Context, !Posn)
).
-:- pred get_float_exponent_3(io.input_stream::in, list(char)::in, token::out,
- io::di, io::uo) is det.
-
% We've read past the first digit of the exponent -
% now get the remaining digits.
%
+:- pred get_float_exponent_3(io.input_stream::in, list(char)::in, token::out,
+ io::di, io::uo) is det.
+
get_float_exponent_3(Stream, Chars, Token, !IO) :-
io.read_char_unboxed(Stream, Result, Char, !IO),
(
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list