[Fontconfig] fontconfig: Branch 'wip/threadsafe' - 5 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Sat Oct 6 15:25:37 PDT 2012
Rebased ref, commits from common ancestor:
commit 38dfb8fb8eae3ca61410599890932c8583a906f1
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sat Oct 6 18:15:58 2012 -0400
Fix build stuff
diff --git a/src/Makefile.am b/src/Makefile.am
index a0fd575..3d83d3c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,8 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
+EXTRA_DIST =
+
if OS_WIN32
export_symbols = -export-symbols fontconfig.def
@@ -78,7 +80,7 @@ INCLUDES = \
-DFC_CACHEDIR='"$(FC_CACHEDIR)"' \
-DFONTCONFIG_PATH='"$(BASECONFIGDIR)"'
-EXTRA_DIST = makealias
+EXTRA_DIST += makealias
noinst_HEADERS=fcint.h fcftint.h fcdeprecate.h
@@ -88,7 +90,8 @@ BUILT_SOURCES = $(ALIAS_FILES) \
../fc-case/fccase.h \
../fc-glyphname/fcglyphname.h \
../fc-lang/fclang.h \
- fcobjshash.h
+ fcobjshash.h \
+ fcobjshash.gperf
noinst_PROGRAMS = fcarch
@@ -111,9 +114,10 @@ fcobjshash.h: fcobjshash.gperf
$(AM_V_GEN) $(top_srcdir)/missing --run gperf -m 100 $< > $@.tmp && \
mv -f $@.tmp $@
-EXTRA_DIST = \
+EXTRA_DIST += \
fcobjshash.gperf.h \
- fcobjshash.gperf
+ fcobjshash.gperf \
+ fcobjshash.h
libfontconfig_la_SOURCES = \
fcarch.h \
@@ -178,7 +182,7 @@ fcftaliastail.h: fcftalias.h
fcftalias.h: $(top_srcdir)/src/makealias $(PUBLIC_FT_FILES)
$(AM_V_GEN) sh $(top_srcdir)/src/makealias "$(top_srcdir)/src" fcftalias.h fcftaliastail.h $(PUBLIC_FT_FILES)
-CLEANFILES = $(ALIAS_FILES)
+CLEANFILES = $(ALIAS_FILES) fontconfig.def
fontconfig.def: $(PUBLIC_FILES) $(PUBLIC_FT_FILES)
echo Generating $@
commit 0f6a1d3e2021173e8eee909614b15f42369daa72
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sat Oct 6 18:12:19 2012 -0400
Remove shared-str pool
We used to have a shared-str pool. Removed to make thread-safety
work easier. My measurements show that the extra overhead is not
significant by any means.
diff --git a/src/fcpat.c b/src/fcpat.c
index ebd6e57..92b4cc4 100644
--- a/src/fcpat.c
+++ b/src/fcpat.c
@@ -1023,68 +1023,24 @@ bail0:
return NULL;
}
-#define OBJECT_HASH_SIZE 251
-static struct objectBucket {
- struct objectBucket *next;
- FcChar32 hash;
- int ref_count;
-} *FcObjectBuckets[OBJECT_HASH_SIZE];
+
+/* We used to have a shared-str pool. Removed to make thread-safety
+ * work easier. My measurements show that the extra overhead is not
+ * significant by any means. */
FcBool
FcSharedStrFree (const FcChar8 *name)
{
- FcChar32 hash = FcStringHash (name);
- struct objectBucket **p;
- struct objectBucket *b;
- int size;
-
- for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
- if (b->hash == hash && ((char *)name == (char *) (b + 1)))
- {
- b->ref_count--;
- if (!b->ref_count)
- {
- *p = b->next;
- size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
- size = (size + 3) & ~3;
- FcMemFree (FC_MEM_SHAREDSTR, size);
- free (b);
- }
- return FcTrue;
- }
- return FcFalse;
+ free (name);
+ FcMemFree (FC_MEM_SHAREDSTR, 8);
+ return FcTrue;
}
const FcChar8 *
FcSharedStr (const FcChar8 *name)
{
- FcChar32 hash = FcStringHash (name);
- struct objectBucket **p;
- struct objectBucket *b;
- int size;
-
- for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
- if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
- {
- b->ref_count++;
- return (FcChar8 *) (b + 1);
- }
- size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
- /*
- * workaround valgrind warning because glibc takes advantage of how it knows memory is
- * allocated to implement strlen by reading in groups of 4
- */
- size = (size + 3) & ~3;
- b = malloc (size);
- FcMemAlloc (FC_MEM_SHAREDSTR, size);
- if (!b)
- return NULL;
- b->next = 0;
- b->hash = hash;
- b->ref_count = 1;
- strcpy ((char *) (b + 1), (char *)name);
- *p = b;
- return (FcChar8 *) (b + 1);
+ FcMemAlloc (FC_MEM_SHAREDSTR, 8);
+ return strdup (name);
}
FcBool
commit c9ac52ab54cc42c4e5d253eddb5dc39eff6ac7cb
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sat Oct 6 17:52:39 2012 -0400
Switch .gitignore to git.mk
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 32b9e43..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,100 +0,0 @@
-tags
-TAGS
-*.exe
-*.tar.gz
-.libs
-.deps
-*.o
-*.lo
-*.la
-*~
-*.orig
-*.rej
-ChangeLog
-ChangeLog-*
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.guess
-config.h
-config.h.in
-config.log
-config.status
-config.sub
-configure
-depcomp
-fontconfig-zip
-fontconfig.pc
-fontconfig.spec
-fonts.conf
-install-sh
-doltcompile
-libtool
-ltmain.sh
-missing
-stamp-h1
-manpage.log
-doc/*.3
-doc/confdir.sgml
-doc/edit-sgml
-doc/fcatomic.sgml
-doc/fcblanks.sgml
-doc/fccache.sgml
-doc/fccharset.sgml
-doc/fcconfig.sgml
-doc/fcconstant.sgml
-doc/fcdircache.sgml
-doc/fcfile.sgml
-doc/fcformat.sgml
-doc/fcfontset.sgml
-doc/fcfreetype.sgml
-doc/fclangset.sgml
-doc/fcinit.sgml
-doc/fcmatrix.sgml
-doc/fcobjectset.sgml
-doc/fcobjecttype.sgml
-doc/fcpattern.sgml
-doc/fcstring.sgml
-doc/fcstrset.sgml
-doc/fcvalue.sgml
-doc/fontconfig-devel.pdf
-doc/fontconfig-devel.txt
-doc/fontconfig-devel
-doc/fontconfig-user.html
-doc/fontconfig-user.pdf
-doc/fontconfig-user.txt
-doc/fonts-conf.5
-doc/func.refs
-doc/local-fontconfig-devel.sgml
-doc/local-fontconfig-user.sgml
-doc/version.sgml
-doc/devel-man
-fc-arch/fc-arch
-fc-arch/fcarch.h
-fc-cache/fc-cache
-fc-cache/fc-cache.1
-fc-case/fc-case
-fc-case/fccase.h
-fc-cat/fc-cat
-fc-cat/fc-cat.1
-fc-glyphname/fc-glyphname
-fc-glyphname/fcglyphname.h
-fc-lang/fc-lang
-fc-lang/fclang.h
-fc-list/fc-list
-fc-list/fc-list.1
-fc-match/fc-match
-fc-match/fc-match.1
-fc-pattern/fc-pattern
-fc-pattern/fc-pattern.1
-fc-query/fc-query
-fc-query/fc-query.1
-fc-scan/fc-scan
-fc-scan/fc-scan.1
-src/fcarch
-src/fontconfig.def
-fcalias.h
-fcaliastail.h
-src/fcftalias.h
-src/fcftaliastail.h
diff --git a/Makefile.am b/Makefile.am
index f4203d6..cbc3df0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -148,3 +148,5 @@ debuild-dirs: distdir
$(RM) -r $(distdir).orig
cp -a $(distdir) $(distdir).orig
$(RM) -r $(distdir).orig/debian
+
+-include $(top_srcdir)/git.mk
diff --git a/conf.d/Makefile.am b/conf.d/Makefile.am
index 0f6f59c..e3a26f0 100644
--- a/conf.d/Makefile.am
+++ b/conf.d/Makefile.am
@@ -92,3 +92,5 @@ uninstall-local:
echo $(RM) $$i; \
$(RM) $$i; \
done)
+
+-include $(top_srcdir)/git.mk
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 2e7363c..7d0034e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -213,3 +213,5 @@ htmldoc_DATA += $(srcdir)/$(HTML_DIR)/*
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-cache/Makefile.am b/fc-cache/Makefile.am
index 8f455c8..b4e90a8 100644
--- a/fc-cache/Makefile.am
+++ b/fc-cache/Makefile.am
@@ -66,3 +66,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-case/Makefile.am b/fc-case/Makefile.am
index ad5dc74..bd5486f 100644
--- a/fc-case/Makefile.am
+++ b/fc-case/Makefile.am
@@ -63,3 +63,5 @@ CLEANFILES = $(ALIAS_FILES)
DISTCLEANFILES = $(TARG)
MAINTAINERCLEANFILES = $(TARG)
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-cat/Makefile.am b/fc-cat/Makefile.am
index 8a2939a..9434638 100644
--- a/fc-cat/Makefile.am
+++ b/fc-cat/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-glyphname/Makefile.am b/fc-glyphname/Makefile.am
index 697b5c3..4091538 100644
--- a/fc-glyphname/Makefile.am
+++ b/fc-glyphname/Makefile.am
@@ -58,3 +58,5 @@ CLEANFILES = $(ALIAS_FILES)
DISTCLEANFILES = $(TARG)
MAINTAINERCLEANFILES = $(TARG)
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-lang/Makefile.am b/fc-lang/Makefile.am
index d2eca5b..6a9acd0 100644
--- a/fc-lang/Makefile.am
+++ b/fc-lang/Makefile.am
@@ -309,3 +309,5 @@ ORTH = \
doi.orth \
mni.orth
# ^-------------- Add new orth files here
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-list/Makefile.am b/fc-list/Makefile.am
index 7822ad4..86ac871 100644
--- a/fc-list/Makefile.am
+++ b/fc-list/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-match/Makefile.am b/fc-match/Makefile.am
index d046b79..9ae2922 100644
--- a/fc-match/Makefile.am
+++ b/fc-match/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-pattern/Makefile.am b/fc-pattern/Makefile.am
index fa66006..ffb0d14 100644
--- a/fc-pattern/Makefile.am
+++ b/fc-pattern/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-query/Makefile.am b/fc-query/Makefile.am
index f60c363..e697c16 100644
--- a/fc-query/Makefile.am
+++ b/fc-query/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-scan/Makefile.am b/fc-scan/Makefile.am
index 8909691..1c2ddc7 100644
--- a/fc-scan/Makefile.am
+++ b/fc-scan/Makefile.am
@@ -57,3 +57,5 @@ else
all-local:
clean-local:
endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fontconfig/Makefile.am b/fontconfig/Makefile.am
index 72fec33..99bb4c3 100644
--- a/fontconfig/Makefile.am
+++ b/fontconfig/Makefile.am
@@ -6,3 +6,5 @@ fontconfig_headers= \
fcprivate.h
fontconfiginclude_HEADERS = $(fontconfig_headers)
+
+-include $(top_srcdir)/git.mk
diff --git a/git.mk b/git.mk
new file mode 100644
index 0000000..d5bf7b8
--- /dev/null
+++ b/git.mk
@@ -0,0 +1,227 @@
+# git.mk
+#
+# Copyright 2009, Red Hat, Inc.
+# Copyright 2010,2011 Behdad Esfahbod
+# Written by Behdad Esfahbod
+#
+# Copying and distribution of this file, with or without modification,
+# is permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+#
+# The latest version of this file can be downloaded from:
+# https://raw.github.com/behdad/git.mk/master/git.mk
+# Bugs, etc, should be reported upstream at:
+# https://github.com/behdad/git.mk
+#
+# To use in your project, import this file in your git repo's toplevel,
+# then do "make -f git.mk". This modifies all Makefile.am files in
+# your project to -include git.mk. Remember to add that line to new
+# Makefile.am files you create in your project, or just rerun the
+# "make -f git.mk".
+#
+# This enables automatic .gitignore generation. If you need to ignore
+# more files, add them to the GITIGNOREFILES variable in your Makefile.am.
+# But think twice before doing that. If a file has to be in .gitignore,
+# chances are very high that it's a generated file and should be in one
+# of MOSTLYCLEANFILES, CLEANFILES, DISTCLEANFILES, or MAINTAINERCLEANFILES.
+#
+# The only case that you need to manually add a file to GITIGNOREFILES is
+# when remove files in one of mostlyclean-local, clean-local, distclean-local,
+# or maintainer-clean-local make targets.
+#
+# Note that for files like editor backup, etc, there are better places to
+# ignore them. See "man gitignore".
+#
+# If "make maintainer-clean" removes the files but they are not recognized
+# by this script (that is, if "git status" shows untracked files still), send
+# me the output of "git status" as well as your Makefile.am and Makefile for
+# the directories involved and I'll diagnose.
+#
+# For a list of toplevel files that should be in MAINTAINERCLEANFILES, see
+# Makefile.am.sample in the git.mk git repo.
+#
+# Don't EXTRA_DIST this file. It is supposed to only live in git clones,
+# not tarballs. It serves no useful purpose in tarballs and clutters the
+# build dir.
+#
+# This file knows how to handle autoconf, automake, libtool, gtk-doc,
+# gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu.
+#
+# This makefile provides the following targets:
+#
+# - all: "make all" will build all gitignore files.
+# - gitignore: makes all gitignore files in the current dir and subdirs.
+# - .gitignore: make gitignore file for the current dir.
+# - gitignore-recurse: makes all gitignore files in the subdirs.
+#
+# KNOWN ISSUES:
+#
+# - Recursive configure doesn't work as $(top_srcdir)/git.mk inside the
+# submodule doesn't find us. If you have configure.{in,ac} files in
+# subdirs, add a proxy git.mk file in those dirs that simply does:
+# "include $(top_srcdir)/../git.mk". Add more ..'s to your taste.
+# And add those files to git. See vte/gnome-pty-helper/git.mk for
+# example.
+#
+
+git-all: git-mk-install
+
+git-mk-install:
+ @echo Installing git makefile
+ @any_failed=; \
+ find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \
+ if grep 'include .*/git.mk' $$x >/dev/null; then \
+ echo $$x already includes git.mk; \
+ else \
+ failed=; \
+ echo "Updating $$x"; \
+ { cat $$x; \
+ echo ''; \
+ echo '-include $$(top_srcdir)/git.mk'; \
+ } > $$x.tmp || failed=1; \
+ if test x$$failed = x; then \
+ mv $$x.tmp $$x || failed=1; \
+ fi; \
+ if test x$$failed = x; then : else \
+ echo Failed updating $$x; >&2 \
+ any_failed=1; \
+ fi; \
+ fi; done; test -z "$$any_failed"
+
+.PHONY: git-all git-mk-install
+
+
+### .gitignore generation
+
+$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
+ $(AM_V_GEN) \
+ { \
+ if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \
+ for x in \
+ $(DOC_MODULE)-decl-list.txt \
+ $(DOC_MODULE)-decl.txt \
+ tmpl/$(DOC_MODULE)-unused.sgml \
+ "tmpl/*.bak" \
+ xml html \
+ ; do echo /$$x; done; \
+ fi; \
+ if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
+ for lc in $(DOC_LINGUAS); do \
+ for x in \
+ $(if $(DOC_MODULE),$(DOC_MODULE).xml) \
+ $(DOC_PAGES) \
+ $(DOC_INCLUDES) \
+ ; do echo /$$lc/$$x; done; \
+ done; \
+ for x in \
+ $(_DOC_OMF_ALL) \
+ $(_DOC_DSK_ALL) \
+ $(_DOC_HTML_ALL) \
+ $(_DOC_MOFILES) \
+ $(DOC_H_FILE) \
+ "*/.xml2po.mo" \
+ "*/*.omf.out" \
+ ; do echo /$$x; done; \
+ fi; \
+ if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
+ for lc in $(HELP_LINGUAS); do \
+ for x in \
+ $(HELP_FILES) \
+ "$$lc.stamp" \
+ "$$lc.mo" \
+ ; do echo /$$lc/$$x; done; \
+ done; \
+ fi; \
+ if test "x$(gsettings_SCHEMAS)" = x; then :; else \
+ for x in \
+ $(gsettings_SCHEMAS:.xml=.valid) \
+ $(gsettings__enum_file) \
+ ; do echo /$$x; done; \
+ fi; \
+ if test -f $(srcdir)/po/Makefile.in.in; then \
+ for x in \
+ po/Makefile.in.in \
+ po/Makefile.in \
+ po/Makefile \
+ po/POTFILES \
+ po/stamp-it \
+ po/.intltool-merge-cache \
+ "po/*.gmo" \
+ "po/*.mo" \
+ po/$(GETTEXT_PACKAGE).pot \
+ intltool-extract.in \
+ intltool-merge.in \
+ intltool-update.in \
+ ; do echo /$$x; done; \
+ fi; \
+ if test -f $(srcdir)/configure; then \
+ for x in \
+ autom4te.cache \
+ configure \
+ config.h \
+ stamp-h1 \
+ libtool \
+ config.lt \
+ ; do echo /$$x; done; \
+ fi; \
+ if test "x$(DEJATOOL)" = x; then :; else \
+ for x in \
+ $(DEJATOOL) \
+ ; do echo /$$x.sum; echo /$$x.log; done; \
+ echo /site.exp; \
+ fi; \
+ for x in \
+ .gitignore \
+ $(GITIGNOREFILES) \
+ $(CLEANFILES) \
+ $(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
+ $(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
+ $(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
+ so_locations \
+ .libs _libs \
+ $(MOSTLYCLEANFILES) \
+ "*.$(OBJEXT)" \
+ "*.lo" \
+ $(DISTCLEANFILES) \
+ $(am__CONFIG_DISTCLEAN_FILES) \
+ $(CONFIG_CLEAN_FILES) \
+ TAGS ID GTAGS GRTAGS GSYMS GPATH tags \
+ "*.tab.c" \
+ $(MAINTAINERCLEANFILES) \
+ $(BUILT_SOURCES) \
+ $(DEPDIR) \
+ Makefile \
+ Makefile.in \
+ "*.orig" \
+ "*.rej" \
+ "*.bak" \
+ "*~" \
+ ".*.sw[nop]" \
+ ".dirstamp" \
+ ; do echo /$$x; done; \
+ } | \
+ sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \
+ sed 's@/[.]/@/@g' | \
+ LC_ALL=C sort | uniq > $@.tmp && \
+ mv $@.tmp $@;
+
+all: $(srcdir)/.gitignore gitignore-recurse-maybe
+gitignore: $(srcdir)/.gitignore gitignore-recurse
+
+gitignore-recurse-maybe:
+ @for subdir in $(DIST_SUBDIRS); do \
+ case " $(SUBDIRS) " in \
+ *" $$subdir "*) :;; \
+ *) test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) .gitignore gitignore-recurse-maybe || echo "Skipping $$subdir");; \
+ esac; \
+ done
+gitignore-recurse:
+ @for subdir in $(DIST_SUBDIRS); do \
+ test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) .gitignore gitignore-recurse || echo "Skipping $$subdir"); \
+ done
+
+maintainer-clean: gitignore-clean
+gitignore-clean:
+ -rm -f $(srcdir)/.gitignore
+
+.PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe
diff --git a/src/Makefile.am b/src/Makefile.am
index 58cc50f..a0fd575 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -189,3 +189,5 @@ fontconfig.def: $(PUBLIC_FILES) $(PUBLIC_FT_FILES)
echo LIBRARY libfontconfig- at LIBT_CURRENT_MINUS_AGE@.dll; \
echo VERSION @LIBT_CURRENT at .@LIBT_REVISION@) >$@
@ ! grep -q FcERROR $@ || ($(RM) $@; false)
+
+-include $(top_srcdir)/git.mk
diff --git a/test/Makefile.am b/test/Makefile.am
index 72da8d6..d691027 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,3 +7,5 @@ TESTDATA=4x6.pcf 8x16.pcf out.expected fonts.conf.in
EXTRA_DIST=$(check_SCRIPTS) $(TESTDATA)
CLEANFILES=
+
+-include $(top_srcdir)/git.mk
commit 22a5f865294410ed34bd9d04e66f7d0542d6670e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sat Oct 6 17:52:07 2012 -0400
Minor
diff --git a/src/fcname.c b/src/fcname.c
index 8d63e6c..e85ff76 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -125,7 +125,7 @@ FcObjectName (FcObject object)
return NULL;
}
-static const FcConstant _FcBaseConstants[] = {
+static const FcConstant FcConstants[] = {
{ (FcChar8 *) "thin", "weight", FC_WEIGHT_THIN, },
{ (FcChar8 *) "extralight", "weight", FC_WEIGHT_EXTRALIGHT, },
{ (FcChar8 *) "ultralight", "weight", FC_WEIGHT_EXTRALIGHT, },
@@ -189,7 +189,7 @@ static const FcConstant _FcBaseConstants[] = {
{ (FcChar8 *) "lcdlegacy", "lcdfilter", FC_LCD_LEGACY },
};
-#define NUM_FC_CONSTANTS (sizeof _FcBaseConstants/sizeof _FcBaseConstants[0])
+#define NUM_FC_CONSTANTS (sizeof FcConstants/sizeof FcConstants[0])
FcBool
FcNameRegisterConstants (const FcConstant *consts, int nconsts)
@@ -211,8 +211,8 @@ FcNameGetConstant (const FcChar8 *string)
int i;
for (i = 0; i < NUM_FC_CONSTANTS; i++)
- if (!FcStrCmpIgnoreCase (string, _FcBaseConstants[i].name))
- return &_FcBaseConstants[i];
+ if (!FcStrCmpIgnoreCase (string, FcConstants[i].name))
+ return &FcConstants[i];
return 0;
}
commit 51de848a3e16e1be541988345eec01df0c13392b
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sat Oct 6 17:34:52 2012 -0400
Use a static perfect hash table for object-name lookup
Generated by gperf. A bit fragile, but I think I got it all right.
diff --git a/src/Makefile.am b/src/Makefile.am
index f6ff6e4..58cc50f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,7 +87,8 @@ ALIAS_FILES = fcalias.h fcaliastail.h fcftalias.h fcftaliastail.h
BUILT_SOURCES = $(ALIAS_FILES) \
../fc-case/fccase.h \
../fc-glyphname/fcglyphname.h \
- ../fc-lang/fclang.h
+ ../fc-lang/fclang.h \
+ fcobjshash.h
noinst_PROGRAMS = fcarch
@@ -98,6 +99,22 @@ noinst_PROGRAMS = fcarch
../fc-lang/fclang.h:
cd ../fc-lang && $(MAKE) $(AM_MAKEFLAGS) fclang.h
+fcobjshash.gperf: fcobjshash.gperf.h fcobjs.h
+ $(AM_V_GEN) $(CPP) -I$(top_srcdir) $< | $(GREP) '^[^#]' | awk ' \
+ /CUT_OUT_BEGIN/ { no_write=1; next; }; \
+ /CUT_OUT_END/ { no_write=0; next; }; \
+ { if (!no_write) print; next; }; \
+ ' - > $@.tmp && \
+ mv -f $@.tmp $@
+
+fcobjshash.h: fcobjshash.gperf
+ $(AM_V_GEN) $(top_srcdir)/missing --run gperf -m 100 $< > $@.tmp && \
+ mv -f $@.tmp $@
+
+EXTRA_DIST = \
+ fcobjshash.gperf.h \
+ fcobjshash.gperf
+
libfontconfig_la_SOURCES = \
fcarch.h \
fcatomic.c \
@@ -117,7 +134,9 @@ libfontconfig_la_SOURCES = \
fcmatch.c \
fcmatrix.c \
fcname.c \
+ fcobjs.c \
fcobjs.h \
+ fcobjshash.h \
fcpat.c \
fcserialize.c \
fcstat.c \
diff --git a/src/fcinit.c b/src/fcinit.c
index ab64012..9c3adb5 100644
--- a/src/fcinit.c
+++ b/src/fcinit.c
@@ -155,7 +155,6 @@ FcFini (void)
if (_fcConfig)
FcConfigDestroy (_fcConfig);
- FcObjectFini ();
FcCacheFini ();
if (FcDebug() & FC_DBG_MEMORY)
FcMemReport ();
diff --git a/src/fcint.h b/src/fcint.h
index 842d5f1..74646c7 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -870,12 +870,6 @@ FcObjectName (FcObject object);
FcPrivate FcObjectSet *
FcObjectGetSet (void);
-FcPrivate FcBool
-FcObjectInit (void);
-
-FcPrivate void
-FcObjectFini (void);
-
#define FcObjectCompare(a, b) ((int) a - (int) b)
/* fcpat.c */
@@ -1067,4 +1061,9 @@ FcStrSerializeAlloc (FcSerialize *serialize, const FcChar8 *str);
FcPrivate FcChar8 *
FcStrSerialize (FcSerialize *serialize, const FcChar8 *str);
+/* fcobjs.c */
+
+FcPrivate int
+FcObjectLookupIdByName (const char *str);
+
#endif /* _FC_INT_H_ */
diff --git a/src/fcname.c b/src/fcname.c
index 76c2bfc..8d63e6c 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -28,166 +28,22 @@
#include <string.h>
#include <stdio.h>
-static const FcObjectType _FcBaseObjectTypes[] = {
+static const FcObjectType FcObjects[] = {
#define FC_OBJECT(NAME, Type) { FC_##NAME, Type },
#include "fcobjs.h"
#undef FC_OBJECT
};
-#define NUM_OBJECT_TYPES (sizeof _FcBaseObjectTypes / sizeof _FcBaseObjectTypes[0])
+#define NUM_OBJECT_TYPES ((int) (sizeof FcObjects / sizeof FcObjects[0]))
-typedef struct _FcObjectTypeList FcObjectTypeList;
-
-struct _FcObjectTypeList {
- const FcObjectTypeList *next;
- const FcObjectType *types;
- int ntypes;
-};
-
-static const FcObjectTypeList _FcBaseObjectTypesList = {
- 0,
- _FcBaseObjectTypes,
- NUM_OBJECT_TYPES,
-};
-
-static const FcObjectTypeList *_FcObjectTypes = &_FcBaseObjectTypesList;
-
-#define OBJECT_HASH_SIZE 31
-
-typedef struct _FcObjectBucket {
- struct _FcObjectBucket *next;
- FcChar32 hash;
- FcObject id;
-} FcObjectBucket;
-
-static FcObjectBucket *FcObjectBuckets[OBJECT_HASH_SIZE];
-
-static FcObjectType *FcObjects = (FcObjectType *) _FcBaseObjectTypes;
-static int FcObjectsNumber = NUM_OBJECT_TYPES;
-static int FcObjectsSize = 0;
-static FcBool FcObjectsInited;
-
-static FcObjectType *
-FcObjectInsert (const char *name, FcType type)
-{
- FcObjectType *o;
- if (FcObjectsNumber >= FcObjectsSize)
- {
- int newsize = FcObjectsNumber * 2;
- FcObjectType *newobjects;
-
- if (FcObjectsSize)
- newobjects = realloc (FcObjects, newsize * sizeof (FcObjectType));
- else
- {
- newobjects = malloc (newsize * sizeof (FcObjectType));
- if (newobjects)
- memcpy (newobjects, FcObjects,
- FcObjectsNumber * sizeof (FcObjectType));
- }
- if (!newobjects)
- return NULL;
- FcObjects = newobjects;
- FcObjectsSize = newsize;
- }
- o = &FcObjects[FcObjectsNumber];
- o->object = name;
- o->type = type;
- ++FcObjectsNumber;
- return o;
-}
-
-static FcObject
-FcObjectId (FcObjectType *o)
-{
- return o - FcObjects + 1;
-}
-
-static FcObjectType *
-FcObjectFindByName (const char *object, FcBool insert)
-{
- FcChar32 hash = FcStringHash ((const FcChar8 *) object);
- FcObjectBucket **p;
- FcObjectBucket *b;
- FcObjectType *o;
-
- if (!FcObjectsInited)
- FcObjectInit ();
- for (p = &FcObjectBuckets[hash%OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
- {
- o = FcObjects + b->id - 1;
- if (b->hash == hash && !strcmp (object, (o->object)))
- return o;
- }
- if (!insert)
- return NULL;
- /*
- * Hook it into the hash chain
- */
- b = malloc (sizeof(FcObjectBucket));
- if (!b)
- return NULL;
- object = (const char *) FcStrCopy ((FcChar8 *) object);
- if (!object) {
- free (b);
- return NULL;
- }
- o = FcObjectInsert (object, -1);
- b->next = NULL;
- b->hash = hash;
- b->id = FcObjectId (o);
- *p = b;
- return o;
-}
-
-static FcObjectType *
+static const FcObjectType *
FcObjectFindById (FcObject object)
{
- if (1 <= object && object <= FcObjectsNumber)
- return FcObjects + object - 1;
+ if (1 <= object && object <= NUM_OBJECT_TYPES)
+ return &FcObjects[object - 1];
return NULL;
}
-static FcBool
-FcObjectHashInsert (const FcObjectType *object, FcBool copy)
-{
- FcChar32 hash = FcStringHash ((const FcChar8 *) object->object);
- FcObjectBucket **p;
- FcObjectBucket *b;
- FcObjectType *o;
-
- if (!FcObjectsInited)
- FcObjectInit ();
- for (p = &FcObjectBuckets[hash%OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
- {
- o = FcObjects + b->id - 1;
- if (b->hash == hash && !strcmp (object->object, o->object))
- return FcFalse;
- }
- /*
- * Hook it into the hash chain
- */
- b = malloc (sizeof(FcObjectBucket));
- if (!b)
- return FcFalse;
- if (copy)
- {
- o = FcObjectInsert (object->object, object->type);
- if (!o)
- {
- free (b);
- return FcFalse;
- }
- }
- else
- o = (FcObjectType *) object;
- b->next = NULL;
- b->hash = hash;
- b->id = FcObjectId (o);
- *p = b;
- return FcTrue;
-}
-
FcBool
FcNameRegisterObjectTypes (const FcObjectType *types, int ntypes)
{
@@ -205,16 +61,21 @@ FcNameUnregisterObjectTypes (const FcObjectType *types, int ntypes)
const FcObjectType *
FcNameGetObjectType (const char *object)
{
- return FcObjectFindByName (object, FcFalse);
+ int id = FcObjectLookupIdByName (object);
+
+ if (!id)
+ return NULL;
+
+ return &FcObjects[id - 1];
}
FcBool
FcObjectValidType (FcObject object, FcType type)
{
- FcObjectType *t = FcObjectFindById (object);
+ const FcObjectType *t = FcObjectFindById (object);
if (t) {
- switch (t->type) {
+ switch ((int) t->type) {
case FcTypeDouble:
case FcTypeInteger:
if (type == FcTypeDouble || type == FcTypeInteger)
@@ -237,11 +98,7 @@ FcObjectValidType (FcObject object, FcType type)
FcObject
FcObjectFromName (const char * name)
{
- FcObjectType *o = FcObjectFindByName (name, FcTrue);
-
- if (o)
- return FcObjectId (o);
- return 0;
+ return FcObjectLookupIdByName (name);
}
FcObjectSet *
@@ -252,57 +109,16 @@ FcObjectGetSet (void)
os = FcObjectSetCreate ();
- for (i = 0; i < FcObjectsNumber; i++)
+ for (i = 0; i < NUM_OBJECT_TYPES; i++)
FcObjectSetAdd (os, FcObjects[i].object);
return os;
}
-FcBool
-FcObjectInit (void)
-{
- int i;
-
- if (FcObjectsInited)
- return FcTrue;
-
- FcObjectsInited = FcTrue;
- for (i = 0; i < NUM_OBJECT_TYPES; i++)
- if (!FcObjectHashInsert (&_FcBaseObjectTypes[i], FcFalse))
- return FcFalse;
- return FcTrue;
-}
-
-void
-FcObjectFini (void)
-{
- int i;
- FcObjectBucket *b, *next;
-
- for (i = 0; i < OBJECT_HASH_SIZE; i++)
- {
- for (b = FcObjectBuckets[i]; b; b = next)
- {
- next = b->next;
- free (b);
- }
- FcObjectBuckets[i] = 0;
- }
- for (i = 0; i < FcObjectsNumber; i++)
- if (FcObjects[i].type == -1)
- free ((void*) FcObjects[i].object);
- if (FcObjects != _FcBaseObjectTypes)
- free (FcObjects);
- FcObjects = (FcObjectType *) _FcBaseObjectTypes;
- FcObjectsNumber = NUM_OBJECT_TYPES;
- FcObjectsSize = 0;
- FcObjectsInited = FcFalse;
-}
-
const char *
FcObjectName (FcObject object)
{
- FcObjectType *o = FcObjectFindById (object);
+ const FcObjectType *o = FcObjectFindById (object);
if (o)
return o->object;
@@ -332,7 +148,7 @@ static const FcConstant _FcBaseConstants[] = {
{ (FcChar8 *) "ultracondensed", "width", FC_WIDTH_ULTRACONDENSED },
{ (FcChar8 *) "extracondensed", "width", FC_WIDTH_EXTRACONDENSED },
{ (FcChar8 *) "condensed", "width", FC_WIDTH_CONDENSED },
- { (FcChar8 *) "semicondensed", "width", FC_WIDTH_SEMICONDENSED },
+ { (FcChar8 *) "semicondensed", "width", FC_WIDTH_SEMICONDENSED },
{ (FcChar8 *) "normal", "width", FC_WIDTH_NORMAL },
{ (FcChar8 *) "semiexpanded", "width", FC_WIDTH_SEMIEXPANDED },
{ (FcChar8 *) "expanded", "width", FC_WIDTH_EXPANDED },
@@ -456,7 +272,7 @@ FcNameConvert (FcType type, FcChar8 *string)
FcMatrix m;
v.type = type;
- switch (v.type) {
+ switch ((int) v.type) {
case FcTypeInteger:
if (!FcNameConstant (string, &v.u.i))
v.u.i = atoi ((char *) string);
@@ -594,7 +410,7 @@ FcNameParse (const FcChar8 *name)
if ((c = FcNameGetConstant (save)))
{
t = FcNameGetObjectType ((char *) c->object);
- switch (t->type) {
+ switch ((int) t->type) {
case FcTypeInteger:
case FcTypeDouble:
if (!FcPatternAddInteger (pat, c->object, c->value))
@@ -708,8 +524,6 @@ FcNameUnparseEscaped (FcPattern *pat, FcBool escape)
FcChar8 buf_static[8192];
int i;
FcPatternElt *e;
- const FcObjectTypeList *l;
- const FcObjectType *o;
FcStrBufInit (&buf, buf_static, sizeof (buf_static));
e = FcPatternObjectFindElt (pat, FC_FAMILY_OBJECT);
@@ -726,28 +540,27 @@ FcNameUnparseEscaped (FcPattern *pat, FcBool escape)
if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ? (FcChar8 *) FC_ESCAPE_FIXED : 0))
goto bail0;
}
- for (l = _FcObjectTypes; l; l = l->next)
+ for (i = 0; i < NUM_OBJECT_TYPES; i++)
{
- for (i = 0; i < l->ntypes; i++)
+ FcObject id = i + 1;
+ const FcObjectType *o;
+ o = &FcObjects[i];
+ if (!strcmp (o->object, FC_FAMILY) ||
+ !strcmp (o->object, FC_SIZE))
+ continue;
+
+ e = FcPatternObjectFindElt (pat, id);
+ if (e)
{
- o = &l->types[i];
- if (!strcmp (o->object, FC_FAMILY) ||
- !strcmp (o->object, FC_SIZE))
- continue;
-
- e = FcPatternObjectFindElt (pat, FcObjectFromName (o->object));
- if (e)
- {
- if (!FcNameUnparseString (&buf, (FcChar8 *) ":", 0))
- goto bail0;
- if (!FcNameUnparseString (&buf, (FcChar8 *) o->object, escape ? (FcChar8 *) FC_ESCAPE_VARIABLE : 0))
- goto bail0;
- if (!FcNameUnparseString (&buf, (FcChar8 *) "=", 0))
- goto bail0;
- if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ?
- (FcChar8 *) FC_ESCAPE_VARIABLE : 0))
- goto bail0;
- }
+ if (!FcNameUnparseString (&buf, (FcChar8 *) ":", 0))
+ goto bail0;
+ if (!FcNameUnparseString (&buf, (FcChar8 *) o->object, escape ? (FcChar8 *) FC_ESCAPE_VARIABLE : 0))
+ goto bail0;
+ if (!FcNameUnparseString (&buf, (FcChar8 *) "=", 0))
+ goto bail0;
+ if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ?
+ (FcChar8 *) FC_ESCAPE_VARIABLE : 0))
+ goto bail0;
}
}
return FcStrBufDone (&buf);
diff --git a/src/fcobjs.c b/src/fcobjs.c
new file mode 100644
index 0000000..0e80b49
--- /dev/null
+++ b/src/fcobjs.c
@@ -0,0 +1,44 @@
+/*
+ * fontconfig/src/fclist.c
+ *
+ * Copyright © 2000 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the author(s) not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. The authors make no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "fcint.h"
+
+#include "fcobjshash.h"
+
+#include <string.h>
+
+int
+FcObjectLookupIdByName (const char *str)
+{
+ const struct FcObjectTypeInfo *o = FcObjectTypeLookup (str, strlen (str));
+
+ if (!o)
+ return 0;
+
+ return o->id;
+}
+
+#define __fcobjs__
+#include "fcaliastail.h"
+#undef __fcobjs__
diff --git a/src/fcobjs.h b/src/fcobjs.h
new file mode 100644
index 0000000..1e9067e
--- /dev/null
+++ b/src/fcobjs.h
@@ -0,0 +1,44 @@
+/* DON'T REORDER! The order is part of the cache signature. */
+FC_OBJECT (FAMILY, FcTypeString)
+FC_OBJECT (FAMILYLANG, FcTypeString)
+FC_OBJECT (STYLE, FcTypeString)
+FC_OBJECT (STYLELANG, FcTypeString)
+FC_OBJECT (FULLNAME, FcTypeString)
+FC_OBJECT (FULLNAMELANG, FcTypeString)
+FC_OBJECT (SLANT, FcTypeInteger)
+FC_OBJECT (WEIGHT, FcTypeInteger)
+FC_OBJECT (WIDTH, FcTypeInteger)
+FC_OBJECT (SIZE, FcTypeDouble)
+FC_OBJECT (ASPECT, FcTypeDouble)
+FC_OBJECT (PIXEL_SIZE, FcTypeDouble)
+FC_OBJECT (SPACING, FcTypeInteger)
+FC_OBJECT (FOUNDRY, FcTypeString)
+FC_OBJECT (ANTIALIAS, FcTypeBool)
+FC_OBJECT (HINT_STYLE, FcTypeInteger)
+FC_OBJECT (HINTING, FcTypeBool)
+FC_OBJECT (VERTICAL_LAYOUT, FcTypeBool)
+FC_OBJECT (AUTOHINT, FcTypeBool)
+FC_OBJECT (GLOBAL_ADVANCE, FcTypeBool) /* deprecated */
+FC_OBJECT (FILE, FcTypeString)
+FC_OBJECT (INDEX, FcTypeInteger)
+FC_OBJECT (RASTERIZER, FcTypeString)
+FC_OBJECT (OUTLINE, FcTypeBool)
+FC_OBJECT (SCALABLE, FcTypeBool)
+FC_OBJECT (DPI, FcTypeDouble)
+FC_OBJECT (RGBA, FcTypeInteger)
+FC_OBJECT (SCALE, FcTypeDouble)
+FC_OBJECT (MINSPACE, FcTypeBool)
+FC_OBJECT (CHAR_WIDTH, FcTypeInteger)
+FC_OBJECT (CHAR_HEIGHT, FcTypeInteger)
+FC_OBJECT (MATRIX, FcTypeMatrix)
+FC_OBJECT (CHARSET, FcTypeCharSet)
+FC_OBJECT (LANG, FcTypeLangSet)
+FC_OBJECT (FONTVERSION, FcTypeInteger)
+FC_OBJECT (CAPABILITY, FcTypeString)
+FC_OBJECT (FONTFORMAT, FcTypeString)
+FC_OBJECT (EMBOLDEN, FcTypeBool)
+FC_OBJECT (EMBEDDED_BITMAP, FcTypeBool)
+FC_OBJECT (DECORATIVE, FcTypeBool)
+FC_OBJECT (LCD_FILTER, FcTypeInteger)
+FC_OBJECT (NAMELANG, FcTypeString)
+/* ^-------------- Add new objects here. */
diff --git a/src/fcobjshash.gperf.h b/src/fcobjshash.gperf.h
new file mode 100644
index 0000000..94002b1
--- /dev/null
+++ b/src/fcobjshash.gperf.h
@@ -0,0 +1,26 @@
+%{
+CUT_OUT_BEGIN
+#include <fontconfig/fontconfig.h>
+CUT_OUT_END
+%}
+%struct-type
+%language=C
+%includes
+%enum
+%readonly-tables
+%define slot-name name
+%define hash-function-name FcObjectTypeHash
+%define lookup-function-name FcObjectTypeLookup
+
+%pic
+%define string-pool-name FcObjectTypeNamePool
+
+struct FcObjectTypeInfo {
+ int name;
+ int id;
+};
+
+%%
+#define FC_OBJECT(NAME, Type) FC_##NAME, FC_##NAME##_OBJECT
+#include "fcobjs.h"
+#undef FC_OBJECT
More information about the Fontconfig
mailing list