Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates: move access of DATEFORMAT_REGEX_CACHE inside lock #57818

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions stdlib/Dates/src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -416,34 +416,30 @@ function DateFormat(f::AbstractString, locale::DateLocale=ENGLISH)

# To understand this block, please see the comments attached to the definitions of
# DATEFORMAT_REGEX_LOCK, DATEFORMAT_REGEX_HASH, and DATEFORMAT_REGEX_CACHE.
lock(DATEFORMAT_REGEX_LOCK)
try
@lock DATEFORMAT_REGEX_LOCK begin
dateformat_regex_hash = hash(keys(CONVERSION_SPECIFIERS))
if dateformat_regex_hash != DATEFORMAT_REGEX_HASH[]
DATEFORMAT_REGEX_HASH[] = dateformat_regex_hash
DATEFORMAT_REGEX_CACHE[] = compute_dateformat_regex(CONVERSION_SPECIFIERS)
end
finally
unlock(DATEFORMAT_REGEX_LOCK)
end

for m in eachmatch(DATEFORMAT_REGEX_CACHE[], f)
tran = replace(f[prev_offset:prevind(f, m.offset)], r"\\(.)" => s"\1")
for m in eachmatch(DATEFORMAT_REGEX_CACHE[], f)
tran = replace(f[prev_offset:prevind(f, m.offset)], r"\\(.)" => s"\1")

if !isempty(prev)
letter, width = prev
push!(tokens, DatePart{letter}(width, isempty(tran)))
end
if !isempty(prev)
letter, width = prev
push!(tokens, DatePart{letter}(width, isempty(tran)))
end

if !isempty(tran)
push!(tokens, Delim(length(tran) == 1 ? first(tran) : tran))
end
if !isempty(tran)
push!(tokens, Delim(length(tran) == 1 ? first(tran) : tran))
end

letter = f[m.offset]
width = length(m.match)
letter = f[m.offset]
width = length(m.match)

prev = (letter, width)
prev_offset = m.offset + width
prev = (letter, width)
prev_offset = m.offset + width
end
end

tran = replace(f[prev_offset:lastindex(f)], r"\\(.)" => s"\1")
Expand Down