From: Markus Triska Date: Wed, 3 Nov 2021 21:27:41 +0000 (+0100) Subject: use '$first_non_octet'/2 for much faster domain check X-Git-Tag: v0.9.0~36^2~3 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=55dabbe16a4f666d2216aac80062f026773094ba;p=scryer-prolog.git use '$first_non_octet'/2 for much faster domain check --- diff --git a/src/lib/crypto.pl b/src/lib/crypto.pl index 0e31f3de..a6f7ad0e 100644 --- a/src/lib/crypto.pl +++ b/src/lib/crypto.pl @@ -46,6 +46,7 @@ :- use_module(library(format)). :- use_module(library(charsio)). :- use_module(library(si)). +:- use_module(library(iso_ext), [partial_string/1]). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - hex_bytes(?Hex, ?Bytes) is det. @@ -104,12 +105,18 @@ must_be_bytes(Bytes, Context) :- must_be_byte_chars(Chars, Context) :- - must_be(list, Chars), - ( member(Char, Chars), - char_code(Char, Code), - \+ between(0, 255, Code) -> - domain_error(byte_char, Char, Context) - ; true + ( partial_string(Chars) -> + ( '$first_non_octet'(Chars, F) -> + domain_error(byte_char, F, Context) + ; true + ) + ; must_be(list, Chars), + ( member(Char, Chars), + char_code(Char, Code), + \+ between(0, 255, Code) -> + domain_error(byte_char, Char, Context) + ; true + ) ).