[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] smooth_malloc 7e7c3489a 1/3: Switch to dynamic memory alloca
From: |
Werner Lemberg |
Subject: |
[freetype2] smooth_malloc 7e7c3489a 1/3: Switch to dynamic memory allocation. |
Date: |
Fri, 6 Oct 2023 23:03:43 -0400 (EDT) |
branch: smooth_malloc
commit 7e7c3489afd87788e2bc083c54d4ed0acb93b6c8
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
Switch to dynamic memory allocation.
This is a proof of concept for benchmarking.
* src/smooth/ftgrays.c (gray_TWorker): Store `memory`.
(gray_convert_glyph): Allocate memory dynamically and handle errors.
(gray_raster_render): Set memory.
---
src/smooth/ftgrays.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index fbf1541ef..2ece39e5c 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -490,6 +490,7 @@ typedef ptrdiff_t FT_PtrDist;
typedef struct gray_TWorker_
{
ft_jmp_buf jump_buffer;
+ FT_Memory memory;
TCoord min_ex, max_ex; /* min and max integer pixel coordinates */
TCoord min_ey, max_ey;
@@ -1958,7 +1959,10 @@ typedef ptrdiff_t FT_PtrDist;
const TCoord yMin = ras.min_ey;
const TCoord yMax = ras.max_ey;
- TCell buffer[FT_MAX_GRAY_POOL];
+ FT_Error error = FT_THROW( Ok );
+ FT_Memory memory = ras.memory;
+
+ TCell* buffer;
size_t height = (size_t)( yMax - yMin );
size_t n = FT_MAX_GRAY_POOL / 8;
TCoord y;
@@ -1968,6 +1972,9 @@ typedef ptrdiff_t FT_PtrDist;
int continued = 0;
+ if ( FT_QNEW_ARRAY( buffer, FT_MAX_GRAY_POOL ) )
+ return error;
+
/* Initialize the null cell at the end of the poll. */
ras.cell_null = buffer + FT_MAX_GRAY_POOL - 1;
ras.cell_null->x = CELL_MAX_X_VALUE;
@@ -1999,7 +2006,6 @@ typedef ptrdiff_t FT_PtrDist;
{
TCoord width = band[0] - band[1];
TCoord w;
- int error;
for ( w = 0; w < width; ++w )
@@ -2028,7 +2034,7 @@ typedef ptrdiff_t FT_PtrDist;
continue;
}
else if ( error != Smooth_Err_Raster_Overflow )
- return error;
+ goto Exit;
/* render pool overflow; we will reduce the render band by half */
width >>= 1;
@@ -2037,7 +2043,8 @@ typedef ptrdiff_t FT_PtrDist;
if ( width == 0 )
{
FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" ));
- return FT_THROW( Raster_Overflow );
+ error = FT_THROW( Raster_Overflow );
+ goto Exit;
}
band++;
@@ -2046,7 +2053,9 @@ typedef ptrdiff_t FT_PtrDist;
} while ( band >= bands );
}
- return Smooth_Err_Ok;
+ Exit:
+ FT_FREE( buffer );
+ return error;
}
@@ -2132,6 +2141,8 @@ typedef ptrdiff_t FT_PtrDist;
if ( ras.max_ex <= ras.min_ex || ras.max_ey <= ras.min_ey )
return Smooth_Err_Ok;
+ ras.memory = (FT_Memory)((gray_PRaster)raster)->memory;
+
return gray_convert_glyph( RAS_VAR );
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] smooth_malloc 7e7c3489a 1/3: Switch to dynamic memory allocation.,
Werner Lemberg <=