Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2021-05-04 20:37:25 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-05-04 20:37:25 +0300
commit621f92cb7f072997366bb385f4f25059c012b6f3 (patch)
treef194f7c971ace359fbb1ca76013d3a4c48442d57 /src/Platform/Heap.cpp
parent0dcb8a79a99e1fe0a9644f8c9d5bf768dd598075 (diff)
Reduce stack usage of EvaluateExpression (thanks Andy)
Also allow '"' or '(' to terminate a meta-command word Removed an unused function
Diffstat (limited to 'src/Platform/Heap.cpp')
-rw-r--r--src/Platform/Heap.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/Platform/Heap.cpp b/src/Platform/Heap.cpp
index 1f7f389a..5f34a6f6 100644
--- a/src/Platform/Heap.cpp
+++ b/src/Platform/Heap.cpp
@@ -353,6 +353,29 @@ StringHandle::StringHandle(const char *s, size_t len) noexcept
}
}
+#if 0 // This constructor is currently unused, but may be useful in future
+// Build a handle by concatenating two strings
+StringHandle::StringHandle(const char *s1, const char *s2) noexcept
+{
+ const size_t len = strlen(s1) + strlen(s2);
+ if (len == 0)
+ {
+ slotPtr = nullptr;
+ }
+ else
+ {
+ WriteLocker locker(heapLock); // prevent other tasks modifying the heap
+ IndexSlot * const slot = AllocateHandle();
+ StorageSpace * const space = AllocateSpace(len + 1);
+ SafeStrncpy(space->data, s1, space->length);
+ SafeStrncat(space->data, s2, space->length);
+ slot->storage = space;
+ slot->refCount = 1;
+ slotPtr = slot;
+ }
+}
+#endif
+
void StringHandle::Assign(const char *s) noexcept
{
Delete();
@@ -366,11 +389,9 @@ void StringHandle::Assign(const char *s) noexcept
void StringHandle::InternalAssign(const char *s, size_t len) noexcept
{
- IndexSlot * const slot = AllocateHandle(); // allocate a handle
+ IndexSlot * const slot = AllocateHandle();
StorageSpace * const space = AllocateSpace(len + 1);
- const size_t lengthToCopy = min<size_t>(len, space->length - 1); // truncate the string if it won't fit
- memcpy(space->data, s, lengthToCopy);
- space->data[lengthToCopy] = 0;
+ SafeStrncpy(space->data, s, space->length);
slot->storage = space;
slot->refCount = 1;
slotPtr = slot;
@@ -380,7 +401,7 @@ void StringHandle::Delete() noexcept
{
if (slotPtr != nullptr)
{
- ReadLocker locker(heapLock); // prevent other tasks modifying the heap
+ ReadLocker locker(heapLock); // prevent other tasks modifying the heap
InternalDelete();
}
}