SDL_image: nanosvgrast.h: light speed up of nsvg__flattenCubicBez()

From d954512e25865e0c8d4d821911f255ba01efa753 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 7 May 2022 14:56:50 +0300
Subject: [PATCH] nanosvgrast.h: light speed up of nsvg__flattenCubicBez()

Removes unnecessary recursive call at last level.  From
mainstream PR/200, patch authored by Filip Sykala.
---
 nanosvgrast.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/nanosvgrast.h b/nanosvgrast.h
index 9ec3e55..e0a9f6a 100644
--- a/nanosvgrast.h
+++ b/nanosvgrast.h
@@ -341,10 +341,11 @@ static void nsvg__flattenCubicBez(NSVGrasterizer* r,
 								  float x3, float y3, float x4, float y4,
 								  int level, int type)
 {
+	const int max_level = 10;
 	float x12,y12,x23,y23,x34,y34,x123,y123,x234,y234,x1234,y1234;
 	float dx,dy,d2,d3;
 
-	if (level > 10) return;
+	if (level > max_level) return;
 
 	x12 = (x1+x2)*0.5f;
 	y12 = (y1+y2)*0.5f;
@@ -364,14 +365,16 @@ static void nsvg__flattenCubicBez(NSVGrasterizer* r,
 		nsvg__addPathPoint(r, x4, y4, type);
 		return;
 	}
-
+	++level;
+	if (level > max_level) return;
+	
 	x234 = (x23+x34)*0.5f;
 	y234 = (y23+y34)*0.5f;
 	x1234 = (x123+x234)*0.5f;
 	y1234 = (y123+y234)*0.5f;
 
-	nsvg__flattenCubicBez(r, x1,y1, x12,y12, x123,y123, x1234,y1234, level+1, 0);
-	nsvg__flattenCubicBez(r, x1234,y1234, x234,y234, x34,y34, x4,y4, level+1, type);
+	nsvg__flattenCubicBez(r, x1,y1, x12,y12, x123,y123, x1234,y1234, level, 0);
+	nsvg__flattenCubicBez(r, x1234,y1234, x234,y234, x34,y34, x4,y4, level, type);
 }
 
 static void nsvg__flattenShape(NSVGrasterizer* r, NSVGshape* shape, float scale)