Hello,

Am 07.07.2015 um 23:19 schrieb Albert Astals Cid:
> Can you please adjust the 
> 
> "// 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."
> 
> Which doesn't make sense anymore?

I attached an updated wording, or do you mean that the comment about
rounding does not apply anymore? (The only definite thing that I found
was that ptmalloc's minimum allocation size is usually 32.)

Best regards, Adam.
From f41b5131b16f6084224cb13d4cfaea8dc72039b2 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Mon, 29 Jun 2015 10:57:20 +0200
Subject: [PATCH] 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.
---
 goo/GooString.h           | 23 +++++++++++++++--------
 qt4/tests/check_lexer.cpp |  2 +-
 qt5/tests/check_lexer.cpp |  2 +-
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/goo/GooString.h b/goo/GooString.h
index c6fb100..3175c9f 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -114,13 +114,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 +171,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);
-- 
2.4.5

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to