goo/GooString.h | 24 ++++++++++++++++-------- qt4/tests/check_lexer.cpp | 2 +- qt5/tests/check_lexer.cpp | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-)
New commits: commit 17adfc848f99a5c5bfad35c94289ccf03fba1a16 Author: Adam Reichold <[email protected]> Date: Sun Jul 12 17:05:24 2015 +0200 Adjust memory layout computation of GooString GooString uses the small string optimization but the static buffer size is hard-coded and hence the final object size becomes dependent on architecture. This adds a helper class to compute the memory layout at compile time so that the target object size of e.g. 32 or another multiple of 16 is achieved. This also adds an overload so that the C string returned by GooString's getCString method respect the constness of this and fixes a constness issue in the lexer tests. diff --git a/goo/GooString.h b/goo/GooString.h index c6fb100..776dd59 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -20,6 +20,7 @@ // Copyright (C) 2008-2010, 2012, 2014 Albert Astals Cid <[email protected]> // Copyright (C) 2012-2014 Fabio D'Urso <[email protected]> // Copyright (C) 2013 Jason Crain <[email protected]> +// Copyright (C) 2015 Adam Reichold <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -114,13 +115,14 @@ public: ~GooString(); // Get length. - int getLength() { return length; } + int getLength() const { return length; } // Get C string. - char *getCString() const { return s; } + char *getCString() { return s; } + const char *getCString() const { return s; } // Get <i>th character. - char getChar(int i) { return s[i]; } + char getChar(int i) const { return s[i]; } // Change <i>th character. void setChar(int i, char c) { s[i] = c; } @@ -170,11 +172,17 @@ private: GooString(const GooString &other); GooString& operator=(const GooString &other); - // you can tweak this number for a different speed/memory usage tradeoffs. - // In libc malloc() rounding is 16 so it's best to choose a value that - // results in sizeof(GooString) be a multiple of 16. - // 24 makes sizeof(GooString) to be 32. - static const int STR_STATIC_SIZE = 24; + // You can tweak the final object size for different time/space tradeoffs. + // In libc malloc(), rounding is 16 so it's best to choose a value that + // is a multiple of 16. + class MemoryLayout { + char c[sizeof(char*)]; + int i; + char* s; + }; + + static const int STR_FINAL_SIZE = 32; + static const int STR_STATIC_SIZE = STR_FINAL_SIZE - sizeof(MemoryLayout) + sizeof(char*); int roundedSize(int len); diff --git a/qt4/tests/check_lexer.cpp b/qt4/tests/check_lexer.cpp index ea834c8..243a592 100644 --- a/qt4/tests/check_lexer.cpp +++ b/qt4/tests/check_lexer.cpp @@ -12,7 +12,7 @@ private slots: void TestLexer::testNumbers() { - char *data = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615"; + char data[] = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615"; Object dummy; MemStream *stream = new MemStream(data, 0, strlen(data), &dummy); Lexer *lexer = new Lexer(NULL, stream); diff --git a/qt5/tests/check_lexer.cpp b/qt5/tests/check_lexer.cpp index ea834c8..243a592 100644 --- a/qt5/tests/check_lexer.cpp +++ b/qt5/tests/check_lexer.cpp @@ -12,7 +12,7 @@ private slots: void TestLexer::testNumbers() { - char *data = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615"; + char data[] = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615"; Object dummy; MemStream *stream = new MemStream(data, 0, strlen(data), &dummy); Lexer *lexer = new Lexer(NULL, stream); _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
