@@ -92,14 +92,10 @@ void PyGlobals::registerValueCaster(MlirTypeID mlirTypeID,
92
92
pybind11::function valueCaster,
93
93
bool replace) {
94
94
pybind11::object &found = valueCasterMap[mlirTypeID];
95
- if (found && !found. is_none () && ! replace)
95
+ if (found && !replace)
96
96
throw std::runtime_error (" Value caster is already registered: " +
97
97
py::repr (found).cast <std::string>());
98
98
found = std::move (valueCaster);
99
- const auto foundIt = valueCasterMapCache.find (mlirTypeID);
100
- if (foundIt != valueCasterMapCache.end () && !foundIt->second .is_none ()) {
101
- valueCasterMapCache[mlirTypeID] = found;
102
- }
103
99
}
104
100
105
101
void PyGlobals::registerDialectImpl (const std::string &dialectNamespace,
@@ -150,35 +146,13 @@ std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
150
146
151
147
std::optional<py::function> PyGlobals::lookupValueCaster (MlirTypeID mlirTypeID,
152
148
MlirDialect dialect) {
153
- {
154
- // Fast match against the value caster map first (common case).
155
- const auto foundIt = valueCasterMapCache.find (mlirTypeID);
156
- if (foundIt != valueCasterMapCache.end ()) {
157
- if (foundIt->second .is_none ())
158
- return std::nullopt;
159
- assert (foundIt->second && " py::function is defined" );
160
- return foundIt->second ;
161
- }
162
- }
163
-
164
- // Not found. Load the dialect namespace.
165
149
loadDialectModule (unwrap (mlirDialectGetNamespace (dialect)));
166
-
167
- // Attempt to find from the canonical map and cache.
168
- {
169
- const auto foundIt = valueCasterMap.find (mlirTypeID);
170
- if (foundIt != valueCasterMap.end ()) {
171
- if (foundIt->second .is_none ())
172
- return std::nullopt;
173
- assert (foundIt->second && " py::object is defined" );
174
- // Positive cache.
175
- valueCasterMapCache[mlirTypeID] = foundIt->second ;
176
- return foundIt->second ;
177
- }
178
- // Negative cache.
179
- valueCasterMap[mlirTypeID] = py::none ();
180
- return std::nullopt;
150
+ const auto foundIt = valueCasterMap.find (mlirTypeID);
151
+ if (foundIt != valueCasterMap.end ()) {
152
+ assert (foundIt->second && " value caster is defined" );
153
+ return foundIt->second ;
181
154
}
155
+ return std::nullopt;
182
156
}
183
157
184
158
std::optional<py::object>
0 commit comments