Skip to content

Commit 2a272b9

Browse files
authored
Do not let _opt_ in a sub-methods use Char. This reduces multiple-recompilations. (#1937)
1 parent fa9518c commit 2a272b9

14 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/common_options.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ function parse_params(d::Dict, cmd::String; del::Bool=true)::String
18381838
end
18391839

18401840
# ---------------------------------------------------------------------------------------------------
1841-
function add_opt_pen(d::Dict, symbs::Union{Nothing, VMs}; opt::String="", del::Bool=true)::String
1841+
function add_opt_pen(d::Dict, @nospecialize(symbs::Union{Nothing, VMs}); opt::String="", del::Bool=true)::String
18421842
# Build a pen option. Input can be either a full hard core string or spread in lw (or lt), lc, ls, etc or a tuple
18431843

18441844
(SHOW_KWARGS[]) && return print_kwarg_opts(symbs, "NamedTuple | Tuple | String | Number") # Just print the options
@@ -2308,9 +2308,9 @@ end
23082308
# ---------------------------------------------------------------------------------------------------
23092309
function add_opt(d::Dict, cmd::String, opt::String, mapa::NamedTuple)::String
23102310
# Thin wrapper: convert NT to Dict to compile _add_opt only once
2311-
_add_opt_1(d, cmd, opt, nt2dict(mapa))
2311+
_add_opt_1(d, cmd, opt, Dict{Symbol,Any}(nt2dict(mapa)))
23122312
end
2313-
function _add_opt_1(d::Dict, cmd::String, opt::String, mapa::Dict)::String
2313+
function _add_opt_1(d::Dict, cmd::String, opt::String, mapa::Dict{Symbol,Any})::String
23142314
cmd_::String = ""
23152315
for k in keys(mapa)
23162316
((val_ = find_in_dict(d, [k], false)[1]) === nothing) && continue # This mapa key was not used
@@ -2339,11 +2339,11 @@ end
23392339
function add_opt(d::Dict, cmd::String, opt::String, symbs::VMs, mapa; grow_mat=nothing, del::Bool=true, expand::Bool=false, expand_str::Bool=false)::String
23402340
# Thin wrapper: convert NamedTuple mapa to Dict to avoid recompilation for each distinct NT type
23412341
mapa_is_nt = isa(mapa, NamedTuple)
2342-
_mapa = mapa_is_nt ? nt2dict(mapa) : mapa
2343-
_add_opt_2(d, cmd, opt, symbs, _mapa; grow_mat=grow_mat, del=del, expand=expand, expand_str=expand_str, mapa_is_nt=mapa_is_nt)
2342+
_mapa = mapa_is_nt ? Dict{Symbol,Any}(nt2dict(mapa)) : (mapa === nothing ? Dict{Symbol,Any}() : mapa)
2343+
_add_opt_2(d, cmd, opt, vec(symbs), _mapa, grow_mat, del, expand, expand_str, mapa_is_nt)
23442344
end
23452345

2346-
function _add_opt_2(d::Dict, cmd::String, opt::String, symbs::VMs, mapa; grow_mat=nothing, del::Bool=true, expand::Bool=false, expand_str::Bool=false, mapa_is_nt::Bool=false)::String
2346+
function _add_opt_2(d::Dict, cmd::String, opt::String, symbs::Vector{Symbol}, @nospecialize(mapa), @nospecialize(grow_mat), del::Bool, expand::Bool, expand_str::Bool, mapa_is_nt::Bool)::String
23472347
# Scan the D Dict for SYMBS keys and if found create the new option OPT and append it to CMD
23482348
# If DEL == false we do not remove the found key.
23492349
# 'grow_mat=mat', is a special case to append to a matrix (can't realy be done in Julia)
@@ -2598,7 +2598,7 @@ function _add_opt_3(d::Dict, cmd::String, opt::String, symbs::VMs, need_symb::Sy
25982598
opt = string(opt,val)
25992599
to_slot = false
26002600
end
2601-
cmd = _add_opt_2(d, cmd, opt, symbs, nt_opts_d; mapa_is_nt=true)
2601+
cmd = _add_opt_2(d, cmd, opt, vec(symbs), nt_opts_d, nothing, true, false, false, true)
26022602
elseif (isa(val, Array{<:Real}) || isa(val, GDtype) || isa(val, GMTcpt) || typeof(val) <: AbstractRange)
26032603
if (typeof(val) <: AbstractRange) val = collect(val) end
26042604
cmd = string(cmd, " -", opt)
@@ -2717,18 +2717,18 @@ function add_opt_fill(d::Dict, opt::String="")
27172717
add_opt_fill(d, [collect(keys(d))[1]], opt) # Use ONLY when len(d) == 1
27182718
end
27192719
add_opt_fill(d::Dict, symbs::VMs, opt="") = add_opt_fill("", d, symbs, opt)
2720-
function add_opt_fill(cmd::String, d::Dict, symbs::VMs, opt="", del::Bool=true)::String
2720+
function add_opt_fill(cmd::String, d::Dict, @nospecialize(symbs::VMs), opt::String="", del::Bool=true)::String
27212721
# Deal with the area fill attributes option. Normally, -G
27222722
(SHOW_KWARGS[]) && return print_kwarg_opts(symbs, "NamedTuple | Tuple | Array | String | Number")
27232723
((val = find_in_dict(d, symbs, del)[1]) === nothing) && return cmd
27242724
isa(val, AbstractDict) && (val = Base.invokelatest(dict2nt, val))
27252725
(val == true && symbs == [:G :fill]) && (val="#0072BD") # Let fill=true mean a default color
27262726
(val == "" && symbs == [:G :fill]) && return cmd # Let fill="" mean no fill (handy for proggy reasons)
2727-
(opt != "") && (opt = string(" -", opt))
2727+
(opt !== "") && (opt = string(" -", opt))
27282728
return add_opt_fill(val, cmd, opt)
27292729
end
27302730

2731-
function add_opt_fill(@nospecialize(val), cmd::String="", opt="")::String
2731+
function add_opt_fill(@nospecialize(val), cmd::String="", opt::String="")::String
27322732
# This method can be called directy with VAL as a NT or a string
27332733
if (isa(val, Tuple) && length(val) == 2 && (isa(val[1], Tuple) || isa(val[1], NamedTuple)))
27342734
# wiggle, for example, may want to repeat the call to fill (-G). Then we expect a Tuple of -G's
@@ -2737,7 +2737,7 @@ function add_opt_fill(@nospecialize(val), cmd::String="", opt="")::String
27372737
elseif (isvector(val) && length(val) == 2 && isa(val[1], String))
27382738
# The above case works but may be uggly sometimes; e.g. fill=(("red+p",), ("blue+n",))
27392739
# So accept also a vector of strings and do not try to interpret its contents. Ex: fill(["red+p", "blue+n"]
2740-
(opt != "" && !startswith(opt, " -")) && (opt = string(" -", opt))
2740+
(opt !== "" && !startswith(opt, " -")) && (opt = string(" -", opt))
27412741
cmd = cmd * opt * val[1]::String * opt * val[2]::String
27422742
elseif (isa(val, NamedTuple))
27432743
d2::Dict = nt2dict(val)

src/geodesy/psvelo.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function velo(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any})
2727
cmd = (isa(val, String)) ? cmd * " -A" * val : cmd * " -A" * vector_attrib(val)
2828
end
2929

30-
cmd = add_opt_fill(cmd, d, [:E :fill_wedges :uncertaintyfill], 'E')
31-
cmd = add_opt_fill(cmd, d, [:G :fill :fill_symbols], 'G')
30+
cmd = add_opt_fill(cmd, d, [:E :fill_wedges :uncertaintyfill], "E")
31+
cmd = add_opt_fill(cmd, d, [:G :fill :fill_symbols], "G")
3232
cmd = parse_these_opts(cmd, d, [[:D :sigma_scale], [:L :outlines], [:N :no_clip :noclip]])
3333

3434
if (haskey(d, :Se) || haskey(d, :velo_NE)) symbs = [:Se :vel_NE]

src/grdvector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function grdvector_helper(arg1, arg2, K::Bool, O::Bool, d::Dict{Symbol, Any})
147147
defNorm, defHead = @sprintf("%.6g%s", as/2+1e-7, km_u), "yes"
148148

149149
opt_Q = !isbarbs ? parse_Q_grdvec(d, [:Q :vec :vector :arrow], defLen, defHead, defNorm) : ""
150-
!occursin(" -G", opt_Q) && (cmd = add_opt_fill(cmd, d, [:G :fill], 'G')) # If fill not passed in arrow, try from regular option
150+
!occursin(" -G", opt_Q) && (cmd = add_opt_fill(cmd, d, [:G :fill], "G")) # If fill not passed in arrow, try from regular option
151151
cmd *= add_opt_pen(d, [:W :pen], opt="W")
152152
(!occursin(" -C", cmd) && !occursin(" -W", cmd) && !occursin(" -G", opt_Q)) && (cmd *= " -W0.5") # If still nothing, set -W.
153153
(opt_Q != "") && (cmd *= opt_Q)

src/pscoast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function coast_parser(first::Bool, clip::String, O::Bool, d::Dict{Symbol, Any})
152152
cmd = parse_Td(d, cmd)
153153
cmd = parse_Tm(d, cmd)
154154
cmd = parse_L(d, cmd)
155-
cmd = add_opt_fill(cmd, d, [:G :land], 'G')
156-
cmd = add_opt_fill(cmd, d, [:S :water :ocean], 'S')
155+
cmd = add_opt_fill(cmd, d, [:G :land], "G")
156+
cmd = add_opt_fill(cmd, d, [:S :water :ocean], "S")
157157

158158
if (clip !== "")
159159
if (clip == "land") cmd *= " -Gc"

src/pshistogram.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function histogram_helper(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol,A
120120
cmd = parse_common_opts(d, cmd, [:UVXY :JZ :c :e :f :p :t :w :params :margin]; first=!O)[1]
121121
cmd = parse_these_opts(cmd, d, [[:A :horizontal], [:F :center], [:Q :cumulative], [:S :stairs]])
122122
nofill = ((symb = is_in_dict(d, [:G :fill])) !== nothing && d[symb] == "") ? true : false # To know if no fill was asked
123-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
123+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
124124
cmd = add_opt(d, cmd, "D", [:D :annot :annotate :counts], (beneath = "_+b", font = "+f", offset = "+o", vertical = "_+r"))
125125
cmd = parse_INW_coast(d, [[:N :distribution :normal]], cmd, "N")
126126
(SHOW_KWARGS[]) && print_kwarg_opts(symbs, "NamedTuple | Tuple | Dict | String")

src/psmask.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function mask(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any})
8989
return isinv ? mat2img(collect(arg1.z .<= thres), arg1) : mat2img(collect(arg1.z .>= thres), arg1)
9090
end
9191

92-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
92+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
9393
cmd = gmt_proggy * cmd
9494
((r = check_dbg_print_cmd(d, cmd)) !== nothing) && return r
9595
prep_and_call_finish_PS_module(d, cmd, "", K, O, true, arg1)

src/psrose.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function rose_helper(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any})
109109

110110
cmd = add_opt(d, cmd, "E", [:E :vectors])
111111
cmd, arg1, arg2, = add_opt_cpt(d, cmd, CPTaliases, 'C', N_args, arg1, arg2)
112-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
112+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
113113
cmd *= opt_pen(d, 'W', [:W :pen])
114114

115115
_cmd = [gmt_proggy * cmd]

src/pssolar.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function solar(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any})
5454
cmd, = parse_common_opts(d, cmd, [:bo :c :h :o :p :t :UVXY :params]; first=!O)
5555
cmd = parse_these_opts(cmd, d, [[:C :format], [:M :dump], [:N :invert]])
5656

57-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
57+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
5858
cmd = add_opt(d, cmd, "I", [:I :sun], (pos="",date="+d",TZ="+z"))
5959
cmd = add_opt(d, cmd, "T", [:T :terminators], (term="",date="+d",TZ="+z"))
6060
cmd *= opt_pen(d, 'W', [:W :pen])

src/pstext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function _text(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol,Any})
119119
cmd = add_opt(d, cmd, "D", [:D :offset], (away=("j", nothing, 1), corners=("J", nothing, 1), shift="", line=("+v",add_opt_pen)))
120120
opt_F = add_opt(d, "", "F", [:F :attrib],
121121
(angle="+a", Angle="+A", font=("+f", font), justify="+j", region_justify="+c", header="_+h", label="_+l", rec_number="_+r", text="+t", zvalues="_+z"); expand=true)
122-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
122+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
123123
contains(cmd, " -G") && (CTRL.pocket_B[3] = ".") # Signal gmt() that it needs to restart because the fill f the API
124124
cmd *= add_opt_pen(d, [:W :pen], opt="W")
125125

src/pswiggle.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function wiggle_helper(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any
8282
(map=("g", arg2str, 1), outside=("J", arg2str, 1), inside=("j", arg2str, 1), norm=("n", arg2str, 1), paper=("x", arg2str, 1), anchor=("", arg2str, 2), width=("+w", arg2str), justify="+j", label_left="_+al", labels="+l", label="+l", offset=("+o", arg2str)), 'j')
8383
cmd *= opt_pen(d, 'T', [:T :track])
8484
cmd *= opt_pen(d, 'W', [:W :pen])
85-
cmd = add_opt_fill(cmd, d, [:G :fill], 'G')
85+
cmd = add_opt_fill(cmd, d, [:G :fill], "G")
8686

8787
_cmd = [gmt_proggy * cmd]
8888
_cmd = frame_opaque(_cmd, gmt_proggy, opt_B, opt_R, opt_J) # No -t in frame

0 commit comments

Comments
 (0)