mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Memory optimisation
This commit is contained in:
@@ -18,6 +18,22 @@ EditorController::EditorController(MenuController * menuController, App * python
|
||||
m_editorView.setTextAreaDelegates(this, this);
|
||||
}
|
||||
|
||||
#ifdef MAX_SCRIPTSIZE
|
||||
void EditorController::setScript(Script script) {
|
||||
m_script = script;
|
||||
Script::Data scriptData = m_script.value();
|
||||
size_t s=scriptData.size,ms=sizeof(m_areaBuffer);
|
||||
if (s>ms)
|
||||
s=ms;
|
||||
size_t availableScriptSize = s + Ion::Storage::sharedStorage()->availableSize();
|
||||
if (availableScriptSize>ms)
|
||||
availableScriptSize=ms;
|
||||
// assert(sizeof(m_areaBuffer) >= availableScriptSize);
|
||||
// We cannot use strlcpy as the first char reprensenting the importation status can be 0.
|
||||
memcpy(m_areaBuffer, (const char *)scriptData.buffer, s);
|
||||
m_editorView.setText(m_areaBuffer+1, availableScriptSize-1); // 1 char is taken by the importation status flag
|
||||
}
|
||||
#else
|
||||
void EditorController::setScript(Script script) {
|
||||
m_script = script;
|
||||
Script::Data scriptData = m_script.value();
|
||||
@@ -27,7 +43,7 @@ void EditorController::setScript(Script script) {
|
||||
memcpy(m_areaBuffer, (const char *)scriptData.buffer, scriptData.size);
|
||||
m_editorView.setText(m_areaBuffer+1, availableScriptSize-1); // 1 char is taken by the importation status flag
|
||||
}
|
||||
|
||||
#endif
|
||||
// TODO: this should be done in textAreaDidFinishEditing maybe??
|
||||
bool EditorController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::Back || event == Ion::Events::Home) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef CODE_EDITOR_CONTROLLER_H
|
||||
#define CODE_EDITOR_CONTROLLER_H
|
||||
|
||||
#define MAX_SCRIPTSIZE 12288
|
||||
|
||||
#include <escher.h>
|
||||
#include "script.h"
|
||||
#include "editor_view.h"
|
||||
@@ -39,7 +41,7 @@ private:
|
||||
/* m_areaBuffer first character is dedicated to the importation status.
|
||||
* Thereby, we avoid wasteful copy while adding the Script to the storage
|
||||
* (in order to add the importation status char before the areaBuffer). */
|
||||
char m_areaBuffer[Ion::Storage::k_storageSize]; // this could be slightly optimize
|
||||
char m_areaBuffer[Ion::Storage::k_storageSize>MAX_SCRIPTSIZE?MAX_SCRIPTSIZE:Ion::Storage::k_storageSize]; // this could be slightly optimize
|
||||
Script m_script;
|
||||
MenuController * m_menuController;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ class StorageDelegate;
|
||||
class Storage {
|
||||
public:
|
||||
typedef uint16_t record_size_t;
|
||||
constexpr static size_t k_storageSize = 16384;
|
||||
constexpr static size_t k_storageSize = 20480;
|
||||
static Storage * sharedStorage();
|
||||
constexpr static char k_dotChar = '.';
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
int numberOfNodes() const;
|
||||
|
||||
private:
|
||||
constexpr static int BufferSize = 32768;
|
||||
constexpr static int BufferSize = 16384;
|
||||
constexpr static int MaxNumberOfNodes = BufferSize/sizeof(TreeNode);
|
||||
static TreePool * SharedStaticPool;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ Expression TrigonometryCheatTable::simplify(const Expression e, ExpressionNode::
|
||||
* For instance, when simplfy a Cosine, we always compute the value for an angle
|
||||
* in the top right trigonometric quadrant. */
|
||||
const TrigonometryCheatTable * TrigonometryCheatTable::Table() {
|
||||
static Row sTableRows[] = {
|
||||
const Row sTableRows[] = {
|
||||
Row(Row::Pair("-90", -90.0f),
|
||||
Row::Pair("π*(-2)^(-1)", -1.5707963267948966f),
|
||||
Row::Pair("-100", -100.0f),
|
||||
|
||||
Reference in New Issue
Block a user