Reducing allocation in FcFontSetSort

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

   I am investigating why FcFontSetSort is allocating and freeing data
around 100000 times. So I first removed the main malloc inside
FcFontSetSort, but that's really not the main source of allocation. In
fact all the allocation is done inside FcSortWalk and freeing is done
by FcCharSetDestroy, when I am calling FcFontSetSort with csp == NULL
and trim == FcTrue. And looking inside FcSortWalk, when trim ==
FcTrue, FcCharSet will be created.
   It's the first time I look at FontConfig source code, and my
understanding of its code is quite limited, so does someone know why
it is needed to create this FcCharSet, as it seems to me that we
allocate/populate just to destroy them. Isn't it possible to change in
file src/fcmatch.c at line 602, the test "if (trim || build_cs)" by
just "if (build_cs)" and remove all this allocation ?

Regards,
-- 
Cedric BAIL
diff --git a/src/fcmatch.c b/src/fcmatch.c
index f104e05..edf94e6 100644
--- a/src/fcmatch.c
+++ b/src/fcmatch.c
@@ -680,12 +680,10 @@ FcFontSetSort (FcConfig	    *config,
 	 nPatternLang++)
 	;
 	
-    /* freed below */
-    nodes = malloc (nnodes * sizeof (FcSortNode) + 
+    /* no need to free */
+    nodes = alloca (nnodes * sizeof (FcSortNode) + 
 		    nnodes * sizeof (FcSortNode *) +
 		    nPatternLang * sizeof (FcBool));
-    if (!nodes)
-	goto bail0;
     nodeps = (FcSortNode **) (nodes + nnodes);
     patternLangSat = (FcBool *) (nodeps + nnodes);
     
@@ -705,7 +703,7 @@ FcFontSetSort (FcConfig	    *config,
 	    }
 	    new->pattern = s->fonts[f];
 	    if (!FcCompare (p, new->pattern, new->score, result))
-		goto bail1;
+		goto bail0;
 	    if (FcDebug () & FC_DBG_MATCHV)
 	    {
 		printf ("Score");
@@ -777,12 +775,12 @@ FcFontSetSort (FcConfig	    *config,
 
     ret = FcFontSetCreate ();
     if (!ret)
-	goto bail1;
+	goto bail0;
 
     cs = 0;
 
     if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim, (csp!=0)))
-	goto bail2;
+	goto bail1;
 
     if (csp)
 	*csp = cs;
@@ -792,8 +790,6 @@ FcFontSetSort (FcConfig	    *config,
             FcCharSetDestroy (cs);
     }
 
-    free (nodes);
-
     if (FcDebug() & FC_DBG_MATCH)
     {
 	printf ("First font ");
@@ -801,12 +797,10 @@ FcFontSetSort (FcConfig	    *config,
     }
     return ret;
 
-bail2:
+bail1:
     if (cs)
 	FcCharSetDestroy (cs);
     FcFontSetDestroy (ret);
-bail1:
-    free (nodes);
 bail0:
     return 0;
 }
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux