Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5bb605

Browse files
committed
Speed improvements in quadmesh. Proper ref-counting in error case.
svn path=/trunk/matplotlib/; revision=5963
1 parent 00fd561 commit f5bb605

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

src/_backend_agg.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,8 @@ class QuadMeshGenerator {
12141214

12151215
private:
12161216
inline unsigned vertex(unsigned idx, double* x, double* y) {
1217-
size_t m = (idx & 0x2) ? (m_m + 1) : m_m;
1218-
size_t n = (idx+1 & 0x2) ? (m_n + 1) : m_n;
1217+
size_t m = m_m + ((idx & 0x2) >> 1);
1218+
size_t n = m_n + ((idx+1 & 0x2) >> 1);
12191219
double* pair = (double*)PyArray_GETPTR2(m_coordinates, n, m);
12201220
*x = *pair++;
12211221
*y = *pair;
@@ -1243,7 +1243,7 @@ class QuadMeshGenerator {
12431243

12441244
inline QuadMeshGenerator(size_t meshWidth, size_t meshHeight, PyObject* coordinates) :
12451245
m_meshWidth(meshWidth), m_meshHeight(meshHeight), m_coordinates(NULL) {
1246-
PyArrayObject* coordinates_array = (PyArrayObject*)PyArray_FromObject(coordinates, PyArray_DOUBLE, 3, 3);
1246+
PyArrayObject* coordinates_array = (PyArrayObject*)PyArray_ContiguousFromObject(coordinates, PyArray_DOUBLE, 3, 3);
12471247
if (!coordinates_array) {
12481248
throw Py::ValueError("Invalid coordinates array.");
12491249
}
@@ -1310,23 +1310,27 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args) {
13101310
}
13111311
}
13121312

1313-
_draw_path_collection_generic<QuadMeshGenerator, 0, 0>
1314-
(master_transform,
1315-
cliprect,
1316-
clippath,
1317-
clippath_trans,
1318-
path_generator,
1319-
transforms_obj,
1320-
offsets_obj,
1321-
offset_trans,
1322-
facecolors_obj,
1323-
edgecolors_obj,
1324-
linewidths,
1325-
linestyles_obj,
1326-
antialiaseds);
1313+
try {
1314+
_draw_path_collection_generic<QuadMeshGenerator, 0, 0>
1315+
(master_transform,
1316+
cliprect,
1317+
clippath,
1318+
clippath_trans,
1319+
path_generator,
1320+
transforms_obj,
1321+
offsets_obj,
1322+
offset_trans,
1323+
facecolors_obj,
1324+
edgecolors_obj,
1325+
linewidths,
1326+
linestyles_obj,
1327+
antialiaseds);
1328+
} catch (...) {
1329+
if (free_edgecolors) Py_XDECREF(edgecolors_obj.ptr());
1330+
throw;
1331+
}
13271332

1328-
if (free_edgecolors)
1329-
Py_XDECREF(edgecolors_obj.ptr());
1333+
if (free_edgecolors) Py_XDECREF(edgecolors_obj.ptr());
13301334

13311335
return Py::Object();
13321336
}

0 commit comments

Comments
 (0)