Repository: matplotlib/matplotlib
File: lib/matplotlib/patches.py (Python)

Code before:
        gc.set_linewidth(lw)
        gc.set_capstyle(self._capstyle)
        gc.set_joinstyle(self._joinstyle)

        gc.set_antialiased(self._antialiased)
        self._set_gc_clip(gc)
        gc.set_url(self._url)
        gc.set_snap(self.get_snap())

        gc.set_alpha(self._alpha)

        if self._hatch:
            gc.set_hatch(self._hatch)
            gc.set_hatch_color(self.get_hatchcolor())
            gc.set_hatch_linewidth(self._hatch_linewidth)

        if self.get_sketch_params() is not None:
            gc.set_sketch_params(*self.get_sketch_params())

        if self.get_path_effects():
            from matplotlib.patheffects import PathEffectRenderer
            renderer = PathEffectRenderer(self.get_path_effects(), renderer)

        # Draw the gaps first if gapcolor is set
        if self.is_dashed() and self._gapcolor is not None:
            gc.set_foreground(colors.to_rgba(self._gapcolor, self._alpha),
                              isRGBA=True)
            offset_gaps, gaps = mlines._get_inverse_dash_pattern(
                *self._dash_pattern)
            gc.set_dashes(offset_gaps, gaps)
            for draw_path_args in draw_path_args_list:
                renderer.draw_path(gc, *draw_path_args)

        # Draw the main edge
        gc.set_foreground(self._edgecolor, isRGBA=True)
        gc.set_dashes(*self._dash_pattern)
        for draw_path_args in draw_path_args_list:
            renderer.draw_path(gc, *draw_path_args)

        gc.restore()
        renderer.close_group('patch')
        self.stale = False

    @artist.allow_rasterization
    def draw(self, renderer):
        # docstring inherited
        if not self.get_visible():
            return
        path = self.get_path()
        transform = self.get_transform()
        tpath = transform.transform_path_non_affine(path)

Review comment (performance):
I think it will be more efficient to do the rgba conversion within `set_gapcolor`, similarly to `set_edgecolor`.  The draw method may be called many times if someone is resizing the gui window.

Code after:
        gc = renderer.new_gc()

        lw = self._linewidth
        if self._edgecolor[3] == 0 or self._linestyle == 'None':
            lw = 0
        gc.set_linewidth(lw)
        gc.set_capstyle(self._capstyle)
        gc.set_joinstyle(self._joinstyle)

        gc.set_antialiased(self._antialiased)
        self._set_gc_clip(gc)
        gc.set_url(self._url)
        gc.set_snap(self.get_snap())

        gc.set_alpha(self._alpha)

        if self._hatch:
            gc.set_hatch(self._hatch)
            gc.set_hatch_color(self.get_hatchcolor())
            gc.set_hatch_linewidth(self._hatch_linewidth)

        if self.get_sketch_params() is not None:
            gc.set_sketch_params(*self.get_sketch_params())

        if self.get_path_effects():
            from matplotlib.patheffects import PathEffectRenderer
            renderer = PathEffectRenderer(self.get_path_effects(), renderer)

        # Draw the gaps first if gapcolor is set
        if self._has_dashed_edge() and self._gapcolor is not None:
            gc.set_foreground(self._gapcolor, isRGBA=True)
            offset_gaps, gaps = mlines._get_inverse_dash_pattern(
                *self._dash_pattern)
            gc.set_dashes(offset_gaps, gaps)
            for draw_path_args in draw_path_args_list:
                renderer.draw_path(gc, *draw_path_args)

        # Draw the main edge
        gc.set_foreground(self._edgecolor, isRGBA=True)
        gc.set_dashes(*self._dash_pattern)
        for draw_path_args in draw_path_args_list:
            renderer.draw_path(gc, *draw_path_args)

        gc.restore()
        renderer.close_group('patch')
        self.stale = False

    @artist.allow_rasterization
    def draw(self, renderer):
        # docstring inherited
        if not self.get_visible():