[Fontconfig] Cleanup patch for ftglue

Behdad Esfahbod behdad at cs.toronto.edu
Tue Mar 7 05:58:16 PST 2006


Hi,

Attached is a cleanup patch that:

  - Fixes a couple compiler warnings.  Namely, an excess
prototype, and old-style function declaration.

  - Cleans up ftglue.h, removing stuff we don't use.

  - Makes get_{char,short,long} functions of ftglue macros to be
inlined.

I'm making a similar change to pango/opentype and the size growth
for that huge code was about 7kb in a 100kb striped binary.  In
fontconfig it's much much less.

--behdad
http://behdad.org/

"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
	-- Dan Bern, "New American Language"
-------------- next part --------------
Index: src/fcfreetype.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcfreetype.c,v
retrieving revision 1.60.2.20
diff -u -p -d -r1.60.2.20 fcfreetype.c
--- src/fcfreetype.c	3 Mar 2006 06:35:53 -0000	1.60.2.20
+++ src/fcfreetype.c	7 Mar 2006 13:54:03 -0000
@@ -2762,7 +2762,7 @@ GetScriptTags(FT_Face face, FT_ULong tab
     if ( ftglue_stream_seek ( stream, base_offset + 4L ) || ftglue_stream_frame_enter( stream, 2L ) )
 	return error;
 
-    new_offset = ((FT_UShort)ftglue_stream_get_short ( stream )) + base_offset;
+    new_offset = GET_UShort() + base_offset;
 
     ftglue_stream_frame_exit( stream );
 
@@ -2776,7 +2776,7 @@ GetScriptTags(FT_Face face, FT_ULong tab
     if ( ftglue_stream_frame_enter( stream, 2L ) )
 	return error;
 
-    *script_count = ((FT_UShort)ftglue_stream_get_short ( stream ));
+    *script_count = GET_UShort ();
 
     ftglue_stream_frame_exit( stream );
 
@@ -2791,8 +2791,8 @@ GetScriptTags(FT_Face face, FT_ULong tab
         if ( ftglue_stream_frame_enter( stream, 6L ) )
 	    goto Fail;
 
-	(*stags)[p] = ((FT_ULong)ftglue_stream_get_long ( stream ));
-	new_offset = ((FT_UShort)ftglue_stream_get_short ( stream )) + base_offset;
+	(*stags)[p] = GET_ULong ();
+	new_offset = GET_UShort () + base_offset;
 
         ftglue_stream_frame_exit( stream );
 
Index: src/fcint.h
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcint.h,v
retrieving revision 1.47.4.38
diff -u -p -d -r1.47.4.38 fcint.h
--- src/fcint.h	3 Mar 2006 18:35:42 -0000	1.47.4.38
+++ src/fcint.h	7 Mar 2006 13:54:03 -0000
@@ -912,9 +912,6 @@ FcPatternEltU (FcPatternEltPtr pei)
     return &_fcPatternElts[FcCacheBankToIndex(pei.bank)][pei.u.stat];
 }
 
-FcPatternElt *
-FcPatternEltU (FcPatternEltPtr pei);
-
 FcValueListPtr
 FcValueListPtrCreateDynamic(FcValueList * p);
 
Index: src/fcname.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcname.c,v
retrieving revision 1.27.4.16
diff -u -p -d -r1.27.4.16 fcname.c
--- src/fcname.c	7 Jan 2006 06:36:24 -0000	1.27.4.16
+++ src/fcname.c	7 Mar 2006 13:54:03 -0000
@@ -358,7 +358,7 @@ FcObjectDistributeBytes (FcCache * metad
 }
 
 void
-FcObjectSerialize ()
+FcObjectSerialize (void)
 {
     int i;
     for (i = 0; i < biggest_known_ntypes; i++)
Index: src/ftglue.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/Attic/ftglue.c,v
retrieving revision 1.1.2.2
diff -u -p -d -r1.1.2.2 ftglue.c
--- src/ftglue.c	21 Feb 2006 15:50:19 -0000	1.1.2.2
+++ src/ftglue.c	7 Mar 2006 13:54:03 -0000
@@ -50,6 +50,14 @@ ftglue_qalloc( FT_Memory  memory,
 
 #undef   QALLOC  /* just in case */
 #define  QALLOC(ptr,size)    ( (ptr) = ftglue_qalloc( memory, (size), &error ), error != 0 )
+#define  FREE(_ptr)                    \
+  do {                                 \
+    if ( (_ptr) )                      \
+    {                                  \
+      ftglue_free( memory, _ptr );     \
+      _ptr = NULL;                     \
+    }                                  \
+  } while (0)
 
 
 FTGLUE_APIDEF( FT_Pointer )
@@ -212,53 +220,6 @@ ftglue_stream_frame_exit( FT_Stream  str
 }
 
 
-FTGLUE_APIDEF( FT_Byte )
-ftglue_stream_get_byte( FT_Stream  stream )
-{
-  FT_Byte  result = 0;
-
-  if ( stream->cursor < stream->limit )
-    result = *stream->cursor++;
-
-  return result;
-}
-
-
-FTGLUE_APIDEF( FT_Short )
-ftglue_stream_get_short( FT_Stream  stream )
-{
-  FT_Byte*  p;
-  FT_Short  result = 0;
-
-  p = stream->cursor;
-  if ( p + 2 <= stream->limit )
-  {
-    result         = (FT_Short)((p[0] << 8) | p[1]);
-    stream->cursor = p+2;
-  }
-  return result;
-}
-
-
-FTGLUE_APIDEF( FT_Long )
-ftglue_stream_get_long( FT_Stream   stream )
-{
-  FT_Byte*  p;
-  FT_Long   result = 0;
-
-  p = stream->cursor;
-  if ( p + 4 <= stream->limit )
-  {
-    result         = (FT_Long)(((FT_Long)p[0] << 24) |
-                               ((FT_Long)p[1] << 16) |
-                               ((FT_Long)p[2] << 8)  |
-                                         p[3]        );
-    stream->cursor = p+4;
-  }
-  return result;
-}
-
-
 FTGLUE_APIDEF( FT_Error )
 ftglue_face_goto_table( FT_Face    face,
                         FT_ULong   the_tag,
Index: src/ftglue.h
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/Attic/ftglue.h,v
retrieving revision 1.1.2.1
diff -u -p -d -r1.1.2.1 ftglue.h
--- src/ftglue.h	19 Nov 2005 22:37:24 -0000	1.1.2.1
+++ src/ftglue.h	7 Mar 2006 13:54:04 -0000
@@ -71,9 +71,17 @@ FT_BEGIN_HEADER
 #define  ACCESS_Frame(size)  SET_ERR( ftglue_stream_frame_enter( stream, size ) )
 #define  FORGET_Frame()      ftglue_stream_frame_exit( stream )
 
-#define  GET_Byte()      ftglue_stream_get_byte( stream )
-#define  GET_Short()     ftglue_stream_get_short( stream )
-#define  GET_Long()      ftglue_stream_get_long( stream )
+#define  GET_Byte()      (*stream->cursor++)
+#define  GET_Short()     (stream->cursor += 2, (FT_Short)( \
+				(*(((FT_Byte*)stream->cursor)-2) << 8) | \
+				 *(((FT_Byte*)stream->cursor)-1) \
+			 ))
+#define  GET_Long()      (stream->cursor += 4, (FT_Long)( \
+				(*(((FT_Byte*)stream->cursor)-4) << 24) | \
+				(*(((FT_Byte*)stream->cursor)-3) << 16) | \
+				(*(((FT_Byte*)stream->cursor)-2) << 8) | \
+				 *(((FT_Byte*)stream->cursor)-1) \
+			 ))
 
 #define  GET_Char()      ((FT_Char)GET_Byte())
 #define  GET_UShort()    ((FT_UShort)GET_Short())
@@ -111,31 +119,6 @@ ftglue_face_goto_table( FT_Face    face,
                         FT_ULong   tag,
                         FT_Stream  stream );
 
-/* memory macros used by the OpenType parser */
-#define  ALLOC(_ptr,_size)   \
-           ( (_ptr) = ftglue_alloc( memory, _size, &error ), error != 0 )
-
-#define  REALLOC(_ptr,_oldsz,_newsz)  \
-           ( (_ptr) = ftglue_realloc( memory, (_ptr), (_oldsz), (_newsz), &error ), error != 0 )
-
-#define  FREE(_ptr)                    \
-  do {                                 \
-    if ( (_ptr) )                      \
-    {                                  \
-      ftglue_free( memory, _ptr );     \
-      _ptr = NULL;                     \
-    }                                  \
-  } while (0)
-
-#define  ALLOC_ARRAY(_ptr,_count,_type)   \
-           ALLOC(_ptr,(_count)*sizeof(_type))
-
-#define  REALLOC_ARRAY(_ptr,_oldcnt,_newcnt,_type) \
-           REALLOC(_ptr,(_oldcnt)*sizeof(_type),(_newcnt)*sizeof(_type))
-
-#define  MEM_Copy(dest,source,count)   memcpy( (char*)(dest), (const char*)(source), (size_t)(count) )
-
-
 FTGLUE_API( FT_Pointer )
 ftglue_alloc( FT_Memory  memory,
               FT_ULong   size,


More information about the Fontconfig mailing list