summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2022-02-18 10:46:57 +0100
committerOliver Sander <oliver.sander@tu-dresden.de>2022-02-21 16:37:51 +0100
commit996dfb015f5567cdaf191c127c2cf804f852d80b (patch)
tree51196310f23e110a1ec86773c99d13a62e59f910 /glib
parentee937d16bbc9f8375fd670b10477d813b1a832ed (diff)
Store the strings in FontInfo in std::optional<std::string>
This saves some memory allocations, because the strings are now stored by value rather than by a pointer pointing to the heap. Also, the costum copy constructor can be replaced by the default one with this change.
Diffstat (limited to 'glib')
-rw-r--r--glib/poppler-document.cc17
1 files changed, 7 insertions, 10 deletions
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 7da76987..9089023c 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -2781,14 +2781,13 @@ G_DEFINE_BOXED_TYPE(PopplerFontsIter, poppler_fonts_iter, poppler_fonts_iter_cop
*/
const char *poppler_fonts_iter_get_full_name(PopplerFontsIter *iter)
{
- const GooString *name;
FontInfo *info;
info = iter->items[iter->index];
- name = info->getName();
- if (name != nullptr) {
- return info->getName()->c_str();
+ std::optional<std::string> name = info->getName();
+ if (name) {
+ return name->c_str();
} else {
return nullptr;
}
@@ -2834,13 +2833,12 @@ const char *poppler_fonts_iter_get_name(PopplerFontsIter *iter)
*/
const char *poppler_fonts_iter_get_substitute_name(PopplerFontsIter *iter)
{
- const GooString *name;
FontInfo *info;
info = iter->items[iter->index];
- name = info->getSubstituteName();
- if (name != nullptr) {
+ std::optional<std::string> name = info->getSubstituteName();
+ if (name) {
return name->c_str();
} else {
return nullptr;
@@ -2858,13 +2856,12 @@ const char *poppler_fonts_iter_get_substitute_name(PopplerFontsIter *iter)
*/
const char *poppler_fonts_iter_get_file_name(PopplerFontsIter *iter)
{
- const GooString *file;
FontInfo *info;
info = iter->items[iter->index];
- file = info->getFile();
- if (file != nullptr) {
+ std::optional<std::string> file = info->getFile();
+ if (file) {
return file->c_str();
} else {
return nullptr;