[poppler] goo/GooString.cc goo/GooString.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Wed May 11 21:36:05 UTC 2016
goo/GooString.cc | 40 ++++++++++++++--------------------------
goo/GooString.h | 10 +++++-----
2 files changed, 19 insertions(+), 31 deletions(-)
New commits:
commit 9c35dc79ec777d9495796124ac7a42bf2b4cf83f
Author: Jakub Kucharski <jakubkucharski97 at gmail.com>
Date: Wed May 11 23:34:53 2016 +0200
goo: refactor GooString::Set()
it is used only once to concatenate strings and it is in a GooString constructor used specifically for that
so I think concatenation should take place in the constructor and GooString::Set
should do exactly what it says which is setting the string.
Bug #94201
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 3f22f36..de9c93c 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -25,6 +25,7 @@
// Copyright (C) 2012 Pino Toscano <pino at kde.org>
// Copyright (C) 2013 Jason Crain <jason at aquaticape.us>
// Copyright (C) 2015 William Bader <williambader at hotmail.com>
+// Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
//
// 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
@@ -176,37 +177,22 @@ void inline GooString::resize(int newLength) {
s[length] = '\0';
}
-GooString* GooString::Set(const char *s1, int s1Len, const char *s2, int s2Len)
+GooString* GooString::Set(const char *newStr, int newLen)
{
- int newLen = 0;
- char *p;
-
- if (s1) {
- if (CALC_STRING_LEN == s1Len) {
- s1Len = strlen(s1);
- } else
- assert(s1Len >= 0);
- newLen += s1Len;
+ if (!newStr) {
+ clear();
+ return this;
}
- if (s2) {
- if (CALC_STRING_LEN == s2Len) {
- s2Len = strlen(s2);
- } else
- assert(s2Len >= 0);
- newLen += s2Len;
+ if (newLen == CALC_STRING_LEN) {
+ newLen = strlen(newStr);
+ } else {
+ assert(newLen >= 0);
}
resize(newLen);
- p = s;
- if (s1) {
- memcpy(p, s1, s1Len);
- p += s1Len;
- }
- if (s2) {
- memcpy(p, s2, s2Len);
- p += s2Len;
- }
+ memmove(s, newStr, newLen);
+
return this;
}
@@ -244,7 +230,9 @@ GooString::GooString(const GooString *str) {
GooString::GooString(GooString *str1, GooString *str2) {
s = NULL;
length = 0;
- Set(str1->getCString(), str1->length, str2->getCString(), str2->length);
+ resize(str1->length + str2->length);
+ memcpy(s, str1->getCString(), str1->length);
+ memcpy(s + str1->length, str2->getCString(), str2->length);
}
GooString *GooString::fromInt(int x) {
diff --git a/goo/GooString.h b/goo/GooString.h
index 776dd59..5ff01ef 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -21,6 +21,7 @@
// Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright (C) 2013 Jason Crain <jason at aquaticape.us>
// Copyright (C) 2015 Adam Reichold <adam.reichold at t-online.de>
+// Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
//
// 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
@@ -65,11 +66,10 @@ public:
// Create a string from <lengthA> chars at <idx> in <str>.
GooString(GooString *str, int idx, int lengthA);
- // Set content of a string to concatination of <s1> and <s2>. They can both
- // be NULL. if <s1Len> or <s2Len> is CALC_STRING_LEN, then length of the string
- // will be calculated with strlen(). Otherwise we assume they are a valid
- // length of string (or its substring)
- GooString* Set(const char *s1, int s1Len=CALC_STRING_LEN, const char *s2=NULL, int s2Len=CALC_STRING_LEN);
+ // Set content of a string to <newStr>. If <newLen> is CALC_STRING_LEN, then
+ // length of the string will be calculated with strlen(). Otherwise we assume
+ // this is a valid length of <newStr> (or its substring)
+ GooString* Set(const char *newStr, int newLen=CALC_STRING_LEN);
// Copy a string.
explicit GooString(const GooString *str);
More information about the poppler
mailing list