further unrolling of string parsing states and elimination of when

guards
This commit is contained in:
alisdair sullivan 2014-12-07 19:12:43 -08:00
parent 8e2d7a0253
commit 4b3fa9b903
2 changed files with 16 additions and 13 deletions

View file

@ -647,16 +647,16 @@ count(<<127, Rest/binary>>, N, Config) ->
count(<<_, Rest/binary>>, N, Config=#config{dirty_strings=true}) -> count(<<_, Rest/binary>>, N, Config=#config{dirty_strings=true}) ->
count(Rest, N + 1, Config); count(Rest, N + 1, Config);
count(<<_/utf8, _/binary>>, N, #config{uescape=true}) -> N; count(<<_/utf8, _/binary>>, N, #config{uescape=true}) -> N;
count(<<X/utf8, Rest/binary>>, N, Config) when X < 16#800 ->
count(Rest, N + 2, Config);
%% u+2028 %% u+2028
count(<<226, 128, 168, _/binary>>, N, _) -> N; count(<<226, 128, 168, _/binary>>, N, _) -> N;
%% u+2029 %% u+2029
count(<<226, 128, 169, _/binary>>, N, _) -> N; count(<<226, 128, 169, _/binary>>, N, _) -> N;
count(<<X/utf8, Rest/binary>>, N, Config) when X < 16#10000 -> count(<<X/utf8, Rest/binary>>, N, Config) ->
count(Rest, N + 3, Config); case X of
count(<<_/utf8, Rest/binary>>, N, Config) -> X when X < 16#800 -> count(Rest, N + 2, Config);
count(Rest, N + 4, Config); X when X < 16#10000 -> count(Rest, N + 3, Config);
_ -> count(Rest, N + 4, Config)
end;
count(_, N, _) -> N. count(_, N, _) -> N.

View file

@ -451,13 +451,16 @@ count(<<126, Rest/binary>>, N, Config) ->
count(<<127, Rest/binary>>, N, Config) -> count(<<127, Rest/binary>>, N, Config) ->
count(Rest, N + 1, Config); count(Rest, N + 1, Config);
count(<<_/utf8, _/binary>>, N, #config{uescape=true}) -> N; count(<<_/utf8, _/binary>>, N, #config{uescape=true}) -> N;
count(<<X/utf8, _/binary>>, N, _) when X == 16#2028; X == 16#2029 -> N; %% u+2028
count(<<X/utf8, Rest/binary>>, N, Config) when X < 16#800 -> count(<<226, 128, 168, _/binary>>, N, _) -> N;
count(Rest, N + 2, Config); %% u+2029
count(<<X/utf8, Rest/binary>>, N, Config) when X < 16#10000 -> count(<<226, 128, 169, _/binary>>, N, _) -> N;
count(Rest, N + 3, Config); count(<<X/utf8, Rest/binary>>, N, Config) ->
count(<<_/utf8, Rest/binary>>, N, Config) -> case X of
count(Rest, N + 4, Config); X when X < 16#800 -> count(Rest, N + 2, Config);
X when X < 16#10000 -> count(Rest, N + 3, Config);
_ -> count(Rest, N + 4, Config)
end;
count(<<_, _/binary>>, N, _) -> N. count(<<_, _/binary>>, N, _) -> N.