@@ -90,7 +90,6 @@ URI(str::AbstractString; kw...) = isempty(kw) ? parse(URI, str) : URI(URI(str);
90
90
91
91
# Based on regex from RFC 3986:
92
92
# https://tools.ietf.org/html/rfc3986#appendix-B
93
- const uri_reference_regex = RegexAndMatchData[]
94
93
function uri_reference_regex_f ()
95
94
r = RegexAndMatchData (r""" ^
96
95
(?: ([^:/?#]+) :) ? # 1. scheme
@@ -107,6 +106,33 @@ function uri_reference_regex_f()
107
106
r
108
107
end
109
108
109
+ if isdefined (Base, :OncePerTask )
110
+ const task_local_regex = OncePerTask {RegexAndMatchData} (uri_reference_regex_f)
111
+ else
112
+ const uri_reference_regex = RegexAndMatchData[]
113
+ function access_threaded (f, v:: Vector )
114
+ tid = Threads. threadid ()
115
+ 0 < tid <= length (v) || _length_assert ()
116
+ if @inbounds isassigned (v, tid)
117
+ @inbounds x = v[tid]
118
+ else
119
+ x = f ()
120
+ @inbounds v[tid] = x
121
+ end
122
+ return x
123
+ end
124
+ @noinline _length_assert () = @assert false " 0 < tid <= v"
125
+
126
+ task_local_regex () = access_threaded (uri_reference_regex_f, uri_reference_regex)
127
+
128
+ function __init__ ()
129
+ nt = isdefined (Base. Threads, :maxthreadid ) ? Threads. maxthreadid () : Threads. nthreads ()
130
+ resize! (empty! (uri_reference_regex), nt)
131
+ return
132
+ end
133
+ end
134
+
135
+
110
136
"""
111
137
https://tools.ietf.org/html/rfc3986#section-3
112
138
"""
@@ -123,7 +149,7 @@ https://tools.ietf.org/html/rfc3986#section-4.1
123
149
"""
124
150
function parse_uri_reference (str:: Union{String, SubString{String}} ;
125
151
strict = false )
126
- uri_reference_re = access_threaded (uri_reference_regex_f, uri_reference_regex )
152
+ uri_reference_re = task_local_regex ( )
127
153
if ! exec (uri_reference_re, str)
128
154
throw (ParseError (" URI contains invalid character" ))
129
155
end
684
710
Base. download (uri:: URI , args... ) = download (uristring (uri), args... )
685
711
686
712
687
- function access_threaded (f, v:: Vector )
688
- tid = Threads. threadid ()
689
- 0 < tid <= length (v) || _length_assert ()
690
- if @inbounds isassigned (v, tid)
691
- @inbounds x = v[tid]
692
- else
693
- x = f ()
694
- @inbounds v[tid] = x
695
- end
696
- return x
697
- end
698
- @noinline _length_assert () = @assert false " 0 < tid <= v"
699
-
700
- function __init__ ()
701
- nt = isdefined (Base. Threads, :maxthreadid ) ? Threads. maxthreadid () : Threads. nthreads ()
702
- resize! (empty! (uri_reference_regex), nt)
703
- return
704
- end
705
-
706
713
include (" deprecate.jl" )
707
714
708
715
end # module
0 commit comments