From f4191888eb6355c5a63fdc20d144e9afa6910950 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 11 Dec 2013 10:47:00 +0100 Subject: QCups: avoid relocations Replace a string (pointer) table with arrays of char arrays of maximally occurring size. In the pageLayoutData case, this is trivial, since all strings have the same size. In the pagesPerSheetData case, I've used a trick to cram the (only) two-digit number into a char[2] array, by following it with a null entry. Effects on AMD64 Linux GCC 4.7 release stripped: text: -352B data: -160B relocs: -14 Change-Id: I6c458ff7ada0f45dab976bbe42b24757fc321302 Reviewed-by: Thiago Macieira --- src/printsupport/kernel/qcups.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/printsupport/kernel') diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp index 1a27fbd07c..b8f75c3cb7 100644 --- a/src/printsupport/kernel/qcups.cpp +++ b/src/printsupport/kernel/qcups.cpp @@ -168,8 +168,11 @@ void QCUPSSupport::setPagesPerSheetLayout(QPrinter *printer, const PagesPerShee const PagesPerSheetLayout pagesPerSheetLayout) { QStringList cupsOptions = cupsOptionsList(printer); - static const char *pagesPerSheetData[] = { "1", "2", "4", "6", "9", "16", 0 }; - static const char *pageLayoutData[] = {"lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl", 0}; + // WARNING: the following trick (with a [2]-extent) only works as + // WARNING: long as there's only one two-digit number in the list + // WARNING: and it is the last one (before the "\0")! + static const char pagesPerSheetData[][2] = { "1", "2", "4", "6", "9", {'1', '6'}, "\0" }; + static const char pageLayoutData[][5] = {"lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl"}; setCupsOption(cupsOptions, QStringLiteral("number-up"), QLatin1String(pagesPerSheetData[pagesPerSheet])); setCupsOption(cupsOptions, QStringLiteral("number-up-layout"), QLatin1String(pageLayoutData[pagesPerSheetLayout])); setCupsOptions(printer, cupsOptions); -- cgit v1.2.3