Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarDirectives.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 03:38:57 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 03:38:57 +1000
commit4585c9cafa87cad6b54397af7e9375cc31b72f89 (patch)
treebefd016a13e95467197b2bd507198b53b262fead /source/core/StarDirectives.cpp
parent14e23a17ccf7d556d98e7dc76f1e7ad81fa70e93 (diff)
Lazy-loading of ImageOperation inside Directives
also fixed cases of drawables not staying centered after adding directives that scale
Diffstat (limited to 'source/core/StarDirectives.cpp')
-rw-r--r--source/core/StarDirectives.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp
index cac1eaf..a18951e 100644
--- a/source/core/StarDirectives.cpp
+++ b/source/core/StarDirectives.cpp
@@ -24,6 +24,14 @@ Directives::Entry::Entry(Entry const& other) {
length = other.length;
}
+ImageOperation const& Directives::Entry::loadOperation(Shared const& parent) const {
+ if (operation.is<NullImageOperation>()) {
+ try { operation = imageOperationFromString(string(parent)); }
+ catch (StarException const& e) { operation = ErrorImageOperation{ std::current_exception() }; }
+ }
+ return operation;
+}
+
StringView Directives::Entry::string(Shared const& parent) const {
StringView result = parent.string;
result = result.utf8().substr(begin, length);
@@ -54,6 +62,15 @@ Directives::Directives(const char* directives) {
parse(directives);
}
+void Directives::loadOperations() const {
+ if (!shared)
+ return;
+
+ MutexLocker lock(shared->mutex, true);
+ for (auto& entry : shared->entries)
+ entry.loadOperation(*shared);
+}
+
void Directives::parse(String&& directives) {
if (directives.empty())
return;
@@ -63,15 +80,19 @@ void Directives::parse(String&& directives) {
StringView prefix = "";
view.forEachSplitView("?", [&](StringView split, size_t beg, size_t end) {
if (!split.empty()) {
- try {
- ImageOperation operation = imageOperationFromString(split);
- newList.emplace_back(move(operation), beg, end);
- }
- catch (StarException const& e) {
- if (beg == 0)
+ if (beg == 0) {
+ try {
+ ImageOperation operation = imageOperationFromString(split);
+ newList.emplace_back(move(operation), beg, end);
+ }
+ catch (StarException const& e) {
prefix = split;
- else
- newList.emplace_back(ErrorImageOperation{ std::current_exception() }, beg, end);
+ return;
+ }
+ }
+ else {
+ ImageOperation operation = NullImageOperation();
+ newList.emplace_back(move(operation), beg, end);
}
}
});
@@ -259,10 +280,11 @@ inline Image DirectivesGroup::applyNewImage(Image const& image) const {
void DirectivesGroup::applyExistingImage(Image& image) const {
forEach([&](auto const& entry, Directives const& directives) {
- if (auto error = entry.operation.ptr<ErrorImageOperation>())
+ ImageOperation const& operation = entry.loadOperation(*directives.shared);
+ if (auto error = operation.ptr<ErrorImageOperation>())
std::rethrow_exception(error->exception);
else
- processImageOperation(entry.operation, image);
+ processImageOperation(operation, image);
});
}