25
25
let bsbuild_cache = Literals. bsbuild_cache
26
26
27
27
28
- type group = {
29
- modules : string array ;
30
- dir_length : int ;
31
- dir_info_offset : int ;
32
- module_info_offset : int ;
33
- }
28
+ type group =
29
+ | Dummy
30
+ | Group of {
31
+ modules : string array ;
32
+ dir_length : int ;
33
+ dir_info_offset : int ;
34
+ module_info_offset : int ;
35
+ }
34
36
35
- type t = group array * string (* string is whole content*)
37
+ type t = {
38
+ lib : group ;
39
+ dev : group ;
40
+ content : string (* string is whole content*)
41
+ }
36
42
37
43
38
44
type cursor = int ref
39
45
40
46
41
47
(* TODO: special case when module_count is zero *)
42
- let rec decode_internal (x : string ) (offset : cursor ) =
43
- (* let len = Ext_pervasives.parse_nat_of_string x offset in
44
- incr offset; *)
48
+ let rec decode_internal (x : string ) : t =
49
+ let (offset : cursor ) = ref 0 in
45
50
let lib = decode_single x offset in
46
51
let dev = decode_single x offset in
47
- [|lib;dev|]
48
- (* if len = 1 then [|first|]
49
- else
50
- let result = Array.make len first in
51
- for i = 1 to len - 1 do
52
- Array.unsafe_set result i (decode_single x offset)
53
- done ;
54
- result
55
- *)
52
+ {lib; dev; content = x}
53
+
56
54
and decode_single (x : string ) (offset : cursor ) : group =
57
55
let module_number = Ext_pervasives. parse_nat_of_string x offset in
58
56
incr offset;
59
- let modules = decode_modules x offset module_number in
60
- let dir_info_offset = ! offset in
61
- let module_info_offset =
62
- String. index_from x dir_info_offset '\n' + 1 in
63
- let dir_length = Char. code x.[module_info_offset] - 48 (* Char.code '0'*) in
64
- offset :=
65
- module_info_offset +
66
- 1 +
67
- dir_length * module_number +
68
- 1
57
+ if module_number <> 0 then begin
58
+ let modules = decode_modules x offset module_number in
59
+ let dir_info_offset = ! offset in
60
+ let module_info_offset =
61
+ String. index_from x dir_info_offset '\n' + 1 in
62
+ let dir_length = Char. code x.[module_info_offset] - 48 (* Char.code '0'*) in
63
+ offset :=
64
+ module_info_offset +
65
+ 1 +
66
+ dir_length * module_number +
67
+ 1
69
68
;
70
- { modules ; dir_info_offset; module_info_offset ; dir_length}
69
+ Group { modules ; dir_info_offset; module_info_offset ; dir_length}
70
+ end else Dummy
71
71
and decode_modules (x : string ) (offset : cursor ) module_number : string array =
72
72
let result = Array. make module_number " " in
73
73
let last = ref ! offset in
@@ -93,7 +93,7 @@ and decode_modules (x : string) (offset : cursor) module_number : string array =
93
93
let read_build_cache ~dir : t =
94
94
let all_content =
95
95
Ext_io. load_file (Filename. concat dir bsbuild_cache) in
96
- decode_internal all_content ( ref ( Ext_digest. length + 1 )), all_content
96
+ decode_internal all_content
97
97
98
98
99
99
@@ -104,11 +104,13 @@ type module_info = {
104
104
105
105
106
106
let find_opt
107
- (( sorteds , whole ) : t )
108
- ( i : int ) (key : string )
107
+ ({ content = whole } as db : t )
108
+ lib (key : string )
109
109
: module_info option =
110
- let group = sorteds.(i) in
111
- let i = Ext_string_array. find_sorted group.modules key in
110
+ match if lib then db.lib else db.dev with
111
+ | Dummy -> None
112
+ | Group ({modules ;} as group ) ->
113
+ let i = Ext_string_array. find_sorted modules key in
112
114
match i with
113
115
| None -> None
114
116
| Some count ->
@@ -134,10 +136,10 @@ let find_opt
134
136
Some {case ; dir_name = String. sub whole dir_name_start (dir_name_finish - dir_name_start)}
135
137
136
138
let find db dependent_module is_not_lib_dir =
137
- let opt = find_opt db 0 dependent_module in
139
+ let opt = find_opt db true dependent_module in
138
140
match opt with
139
141
| Some _ -> opt
140
142
| None ->
141
143
if is_not_lib_dir then
142
- find_opt db 1 dependent_module
144
+ find_opt db false dependent_module
143
145
else None
0 commit comments