Skip to content

Commit

Permalink
Dict->IdDict in exception types (JuliaPy#927)
Browse files Browse the repository at this point in the history
* Dict->IdDict in exception types

Dicts use extensive specialization and this adds latency.
IdDicts don't and are the go-to associative container
for type-keys.

* Rely on `const` to solve inference problems

The `::Dict`, being an abstract annotation, wouldn't have been all
that much help anyway.
  • Loading branch information
timholy authored Oct 24, 2021
1 parent c7b069a commit 4be534b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/exception.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ end
#########################################################################
# Mapping of Julia Exception types to Python exceptions

const pyexc = Dict{DataType, PyPtr}()
const pyexc = IdDict{DataType, PyPtr}()
mutable struct PyIOError <: Exception end

function pyexc_initialize()
Expand Down Expand Up @@ -213,7 +213,7 @@ end

function pyraise(e, bt = nothing)
eT = typeof(e)
pyeT = haskey(pyexc::Dict, eT) ? pyexc[eT] : pyexc[Exception]
pyeT = haskey(pyexc, eT) ? pyexc[eT] : pyexc[Exception]
err = PyJlError(e, bt)
ccall((@pysym :PyErr_SetObject), Cvoid, (PyPtr, PyPtr),
pyeT, PyObject(err))
Expand Down
2 changes: 1 addition & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
function ioraise(e, bt = nothing)
if isa(e, MethodError) || isa(e, ErrorException)
ccall((@pysym :PyErr_SetString), Cvoid, (PyPtr, Cstring),
(pyexc::Dict)[PyIOError],
pyexc[PyIOError],
showerror_string(e, bt))
else
pyraise(e, bt)
Expand Down

0 comments on commit 4be534b

Please sign in to comment.