From 182d3052c5da17701b6407164a6505b8aeafa867 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 31 Aug 2023 03:14:48 +1000 Subject: [PATCH] operator== for Directives, skips reparse if equal --- source/core/StarDirectives.cpp | 26 ++++++++++++++++++++++++++ source/core/StarDirectives.hpp | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp index 3381f1f..dfea7b0 100644 --- a/source/core/StarDirectives.cpp +++ b/source/core/StarDirectives.cpp @@ -62,6 +62,32 @@ Directives::Directives(const char* directives) { parse(directives); } +Directives& Directives::operator=(String const& directives) { + if (shared && shared->string == directives) + return *this; + + parse(String(directives)); + return *this; +} + +Directives& Directives::operator=(String&& directives) { + if (shared && shared->string == directives) { + directives.clear(); + return *this; + } + + parse(move(directives)); + return *this; +} + +Directives& Directives::operator=(const char* directives) { + if (shared && shared->string.utf8().compare(directives) == 0) + return *this; + + parse(directives); + return *this; +} + void Directives::loadOperations() const { if (!shared) return; diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp index 9936c51..d15d095 100644 --- a/source/core/StarDirectives.hpp +++ b/source/core/StarDirectives.hpp @@ -45,6 +45,10 @@ public: Directives(String&& directives); Directives(const char* directives); + Directives& operator=(String const& s); + Directives& operator=(String&& s); + Directives& operator=(const char* s); + void loadOperations() const; void parse(String&& directives); String string() const;