Skip to content

Commit 38615bb

Browse files
authored
Re-enable precompilation for common Parsers routines (#148)
* Re-enable precompilation for common Parsers routines * enable precompile * add compat for SnoopPrecompile * fix compat
1 parent a740baf commit 38615bb

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ version = "2.5.0"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
89

910
[compat]
11+
SnoopPrecompile = "1"
1012
julia = "1.6"
1113

1214
[extras]

src/precompile.jl

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1-
function _precompile_()
2-
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
3-
precompile(Tuple{typeof(Parsers.parse), Type{Int64}, String})
4-
precompile(Tuple{typeof(Parsers.parse), Type{Float64}, String})
5-
precompile(Tuple{typeof(Parsers.parse), Type{Date}, String})
1+
using SnoopPrecompile
2+
3+
@precompile_setup begin
4+
# Putting some things in `setup` can reduce the size of the
5+
# precompile file and potentially make loading faster.
6+
options = Parsers.Options()
7+
pos = 1
8+
val = "123"
9+
len = length(val)
10+
@precompile_all_calls begin
11+
# all calls in this block will be precompiled, regardless of whether
12+
# they belong to your package or not (on Julia 1.8 and higher)
13+
for T in (String, Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
14+
for buf in (codeunits(val), Vector(codeunits(val)))
15+
Parsers.xparse(T, buf, pos, len, options)
16+
Parsers.xparse(T, buf, pos, len, options, Any)
17+
end
18+
end
19+
20+
for T in (Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
21+
for buf in (val, SubString(val, 1:3), Vector(codeunits(val)), view(Vector(codeunits(val)), 1:3))
22+
try
23+
Parsers.parse(T, buf, options)
24+
catch
25+
end
26+
Parsers.tryparse(T, buf, options)
27+
end
28+
end
29+
end
630
end
7-
_precompile_()

0 commit comments

Comments
 (0)