@@ -14,56 +14,51 @@ module Transfer = struct
14
14
end
15
15
16
16
module Header = struct
17
- module Private = struct
18
- external string_unsafe_get64 : string -> int -> int64
19
- = " %caml_string_get64u"
17
+ external string_unsafe_get64 : string -> int -> int64 = " %caml_string_get64u"
20
18
21
- (* [caseless_equal a b] must be equivalent to
22
- [String.equal (String.lowercase_ascii a) (String.lowercase_ascii b)]. *)
23
- let caseless_equal a b =
24
- if a == b then true
25
- else
26
- let len = String. length a in
27
- len = String. length b
28
- (* Note: at this point we konw that [a] and [b] have the same length. *)
29
- &&
30
- (* [word_loop a b i len] compares strings [a] and [b] from
31
- offsets [i] (included) to [len] (excluded), one word at a time.
32
- [i] is a world-aligned index into the strings.
33
- *)
34
- let rec word_loop a b i len =
35
- if i = len then true
19
+ (* [caseless_equal a b] must be equivalent to
20
+ [String.equal (String.lowercase_ascii a) (String.lowercase_ascii b)]. *)
21
+ let caseless_equal a b =
22
+ if a == b then true
23
+ else
24
+ let len = String. length a in
25
+ len = String. length b
26
+ (* Note: at this point we konw that [a] and [b] have the same length. *)
27
+ &&
28
+ (* [word_loop a b i len] compares strings [a] and [b] from
29
+ offsets [i] (included) to [len] (excluded), one word at a time.
30
+ [i] is a world-aligned index into the strings.
31
+ *)
32
+ let rec word_loop a b i len =
33
+ if i = len then true
34
+ else
35
+ let i' = i + 8 in
36
+ (* If [i' > len], what remains to be compared is strictly
37
+ less than a word long, use byte-per-byte comparison. *)
38
+ if i' > len then byte_loop a b i len
39
+ else if string_unsafe_get64 a i = string_unsafe_get64 b i then
40
+ word_loop a b i' len
36
41
else
37
- let i' = i + 8 in
38
- (* If [i' > len], what remains to be compared is strictly
39
- less than a word long, use byte-per-byte comparison. *)
40
- if i' > len then byte_loop a b i len
41
- else if string_unsafe_get64 a i = string_unsafe_get64 b i then
42
- word_loop a b i' len
43
- else
44
- (* If the words at [i] differ, it may due to a case
45
- difference; we check the individual bytes of this
46
- work, and then we continue checking the other
47
- words. *)
48
- byte_loop a b i i' && word_loop a b i' len
49
- (* [byte_loop a b i len] compares the strings [a] and [b] from
50
- offsets [i] (included) to [len] (excluded), one byte at
51
- a time.
52
-
53
- This function assumes that [i < len] holds -- its only called
54
- by [word_loop] when this is known to hold. *)
55
- and byte_loop a b i len =
56
- let c1 = String. unsafe_get a i in
57
- let c2 = String. unsafe_get b i in
58
- Char. lowercase_ascii c1 = Char. lowercase_ascii c2
59
- &&
60
- let i' = i + 1 in
61
- i' = len || byte_loop a b i' len
62
- in
63
- word_loop a b 0 len
64
- end
65
-
66
- let caseless_equal = Private. caseless_equal
42
+ (* If the words at [i] differ, it may due to a case
43
+ difference; we check the individual bytes of this
44
+ work, and then we continue checking the other
45
+ words. *)
46
+ byte_loop a b i i' && word_loop a b i' len
47
+ (* [byte_loop a b i len] compares the strings [a] and [b] from
48
+ offsets [i] (included) to [len] (excluded), one byte at
49
+ a time.
50
+
51
+ This function assumes that [i < len] holds -- its only called
52
+ by [word_loop] when this is known to hold. *)
53
+ and byte_loop a b i len =
54
+ let c1 = String. unsafe_get a i in
55
+ let c2 = String. unsafe_get b i in
56
+ Char. lowercase_ascii c1 = Char. lowercase_ascii c2
57
+ &&
58
+ let i' = i + 1 in
59
+ i' = len || byte_loop a b i' len
60
+ in
61
+ word_loop a b 0 len
67
62
68
63
type t = (string * string ) list
69
64
@@ -351,6 +346,12 @@ module Header = struct
351
346
| Some v when v = " close" -> Some `Close
352
347
| Some x -> Some (`Unknown x)
353
348
| _ -> None
349
+
350
+ module Private = struct
351
+ let caseless_equal = caseless_equal
352
+ let first = first
353
+ let move_to_front = move_to_front
354
+ end
354
355
end
355
356
356
357
module Status = struct
0 commit comments