Skip to content

Commit ce7a6a6

Browse files
committed
Path: change the type of the code type constants to match the type of the code array
The matching types make comparisons between the constants and values of the codes array faster. Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: Before: 9.95 fps After: 15.26 fps The main areas where this helps for the cairo case is the faster comparisons in Path.iter_segments() and in _append_paths() of the cairo backend.
1 parent 8b65fa1 commit ce7a6a6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/matplotlib/path.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ class Path(object):
7474
7575
"""
7676

77+
code_type = np.uint8
78+
7779
# Path codes
78-
STOP = 0 # 1 vertex
79-
MOVETO = 1 # 1 vertex
80-
LINETO = 2 # 1 vertex
81-
CURVE3 = 3 # 2 vertices
82-
CURVE4 = 4 # 3 vertices
83-
CLOSEPOLY = 79 # 1 vertex
80+
STOP = code_type(0) # 1 vertex
81+
MOVETO = code_type(1) # 1 vertex
82+
LINETO = code_type(2) # 1 vertex
83+
CURVE3 = code_type(3) # 2 vertices
84+
CURVE4 = code_type(4) # 3 vertices
85+
CLOSEPOLY = code_type(79) # 1 vertex
8486

8587
#: A dictionary mapping Path codes to the number of vertices that the
8688
#: code expects.
@@ -91,8 +93,6 @@ class Path(object):
9193
CURVE4: 3,
9294
CLOSEPOLY: 1}
9395

94-
code_type = np.uint8
95-
9696
def __init__(self, vertices, codes=None, _interpolation_steps=1,
9797
closed=False, readonly=False):
9898
"""

0 commit comments

Comments
 (0)