From 08c0f029cc6630f147b1681d4864cc42f33be7cc Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 21 May 2017 23:28:17 +1000 Subject: Use UniqueString to simplify FontNames. --- src/ViewStyle.cxx | 23 ++++++++--------------- src/ViewStyle.h | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 39661ddc2..7a0b146f8 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -19,9 +19,7 @@ #include "Scintilla.h" #include "Position.h" -#include "SplitVector.h" -#include "Partitioning.h" -#include "RunStyles.h" +#include "UniqueString.h" #include "Indicator.h" #include "XPM.h" #include "LineMarker.h" @@ -45,26 +43,21 @@ FontNames::~FontNames() { } void FontNames::Clear() { - for (const char *name : names) { - delete []name; - } names.clear(); } const char *FontNames::Save(const char *name) { if (!name) - return 0; + return nullptr; - for (const char *nm : names) { - if (strcmp(nm, name) == 0) { - return nm; + for (const UniqueString &nm : names) { + if (strcmp(nm.get(), name) == 0) { + return nm.get(); } } - const size_t lenName = strlen(name) + 1; - char *nameSave(new char[lenName]); - memcpy(nameSave, name, lenName); - names.push_back(nameSave); - return nameSave; + + names.push_back(UniqueStringCopy(name)); + return names.back().get(); } FontRealised::FontRealised() { diff --git a/src/ViewStyle.h b/src/ViewStyle.h index ad482c814..7210fa610 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -29,7 +29,7 @@ public: */ class FontNames { private: - std::vector names; + std::vector names; public: FontNames(); // FontNames objects can not be copied. -- cgit v1.2.3