[Scummvm-git-logs] scummvm master -> cdb45e65b59b61ecd9b640c1f323e8390ffa58fc
bluegr
noreply at scummvm.org
Mon Mar 3 09:24:10 UTC 2025
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
85a7067bd4 COMMON: Add emplace and rvalue insert to Common::List
cdb45e65b5 COMMON: Add emplace and rvalue insert to Common::Queue
Commit: 85a7067bd4ec0e96919fda8e5e892301d2616466
https://github.com/scummvm/scummvm/commit/85a7067bd4ec0e96919fda8e5e892301d2616466
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-03T11:24:06+02:00
Commit Message:
COMMON: Add emplace and rvalue insert to Common::List
Changed paths:
common/list.h
common/list_intern.h
diff --git a/common/list.h b/common/list.h
index 020e5e9085b..140bd81ac3e 100644
--- a/common/list.h
+++ b/common/list.h
@@ -71,6 +71,15 @@ public:
clear();
}
+ /**
+ * Construct an @p element before @p pos.
+ */
+ template<class... TArgs>
+ iterator emplace(iterator pos, TArgs &&...args) {
+ emplace(pos._node, Common::forward<TArgs>(args)...);
+ return --pos;
+ }
+
/**
* Insert an @p element before @p pos.
*/
@@ -79,6 +88,14 @@ public:
return --pos;
}
+ /**
+ * Insert an @p element before @p pos.
+ */
+ iterator insert(iterator pos, t_T &&element) {
+ insert(pos._node, Common::move(element));
+ return --pos;
+ }
+
/**
* Insert elements from @p first to @p last before @p pos.
*/
@@ -131,16 +148,38 @@ public:
i = i->_next;
}
+ /** Construct an @p element at the start of the list. */
+ template<class... TArgs>
+ void emplace_front(TArgs &&...args) {
+ emplace(_anchor._next, Common::forward<TArgs>(args)...);
+ }
+
/** Insert an @p element at the start of the list. */
void push_front(const t_T &element) {
insert(_anchor._next, element);
}
+ /** Insert an @p element at the start of the list. */
+ void push_front(t_T &&element) {
+ insert(_anchor._next, Common::move(element));
+ }
+
+ /** Construct an @p element at the end of the list. */
+ template<class... TArgs>
+ void emplace_back(TArgs &&...args) {
+ emplace(&_anchor, Common::forward<TArgs>(args)...);
+ }
+
/** Append an @p element to the end of the list. */
void push_back(const t_T &element) {
insert(&_anchor, element);
}
+ /** Append an @p element to the end of the list. */
+ void push_back(t_T &&element) {
+ insert(&_anchor, Common::move(element));
+ }
+
/** Remove the first element of the list. */
void pop_front() {
assert(!empty());
@@ -275,6 +314,20 @@ protected:
return n;
}
+ /**
+ * Construct an @p element before @p pos.
+ */
+ template<class... TArgs>
+ void emplace(NodeBase *pos, TArgs&&... args) {
+ ListInternal::NodeBase *newNode = new Node(Common::forward<TArgs>(args)...);
+ assert(newNode);
+
+ newNode->_next = pos;
+ newNode->_prev = pos->_prev;
+ newNode->_prev->_next = newNode;
+ newNode->_next->_prev = newNode;
+ }
+
/**
* Insert an @p element before @p pos.
*/
@@ -287,6 +340,19 @@ protected:
newNode->_prev->_next = newNode;
newNode->_next->_prev = newNode;
}
+
+ /**
+ * Insert an @p element before @p pos.
+ */
+ void insert(NodeBase *pos, t_T &&element) {
+ ListInternal::NodeBase *newNode = new Node(Common::move(element));
+ assert(newNode);
+
+ newNode->_next = pos;
+ newNode->_prev = pos->_prev;
+ newNode->_prev->_next = newNode;
+ newNode->_next->_prev = newNode;
+ }
};
/** @} */
diff --git a/common/list_intern.h b/common/list_intern.h
index 3d9660c6f53..41161246cfe 100644
--- a/common/list_intern.h
+++ b/common/list_intern.h
@@ -22,7 +22,7 @@
#ifndef COMMON_LIST_INTERN_H
#define COMMON_LIST_INTERN_H
-#include "common/scummsys.h"
+#include "common/util.h"
namespace Common {
@@ -43,6 +43,9 @@ namespace ListInternal {
T _data;
Node(const T &x) : _data(x) {}
+ Node(T &&x) : _data(Common::move(x)) {}
+ template<class... TArgs>
+ Node(TArgs&&... args) : _data(Common::forward<TArgs>(args)...) {}
};
template<typename T> struct ConstIterator;
Commit: cdb45e65b59b61ecd9b640c1f323e8390ffa58fc
https://github.com/scummvm/scummvm/commit/cdb45e65b59b61ecd9b640c1f323e8390ffa58fc
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-03-03T11:24:06+02:00
Commit Message:
COMMON: Add emplace and rvalue insert to Common::Queue
Changed paths:
common/queue.h
diff --git a/common/queue.h b/common/queue.h
index 3302a84c14f..7dd9553a6b4 100644
--- a/common/queue.h
+++ b/common/queue.h
@@ -52,10 +52,19 @@ public:
_impl.clear();
}
+ template<class... TArgs>
+ void emplace(TArgs&&... args) {
+ _impl.emplace_back(Common::forward<TArgs>(args)...);
+ }
+
void push(const T &x) {
_impl.push_back(x);
}
+ void push(T &&x) {
+ _impl.push_back(Common::move(x));
+ }
+
T &front() {
return _impl.front();
}
@@ -73,7 +82,7 @@ public:
}
T pop() {
- T tmp = front();
+ T tmp = Common::move(front());
_impl.pop_front();
return tmp;
}
More information about the Scummvm-git-logs
mailing list