Skip to content

Commit

Permalink
[#143] Small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 20, 2023
1 parent f7e449c commit f2331f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class CommandOutStream {
internal->writeField(field, value);
}

void writeFlagFieldSet(uint8_t field) {
internal->writeField(field, 0);
}

QuotedStringFieldWriter<ZP> beginQuotedString() {
internal->beginBigString();
return QuotedStringFieldWriter<ZP>(internal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ class ScriptSpaceSetupCommand: public script_space_module::ScriptSpaceSetup_Comm
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t spaceIndex = 0;
if (!ctx.getField(ReqScriptSpaceId__P, &spaceIndex)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
} else if (spaceIndex >= Zscript<ZP>::zscript.getScriptSpaceCount()) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqScriptSpaceId__P, Zscript<ZP>::zscript.getScriptSpaceCount(), &spaceIndex)) {
return;
}

CommandOutStream<ZP> out = ctx.getOutStream();
ScriptSpace<ZP> *target = Zscript<ZP>::zscript.getScriptSpaces()[spaceIndex];
out.writeField(RespCurrentWritePosition__P, target->getCurrentLength());
if (target->isRunning()) {
out.writeField(RespRunning__R, 0);
out.writeFlagFieldSet(RespRunning__R);
}
if (target->canBeWrittenTo()) {
out.writeField(RespWriteAllowed__W, 0);
out.writeFlagFieldSet(RespWriteAllowed__W);
}
out.writeField(RespAvailableLength__L, target->getMaxLength());
uint16_t runOpt = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ class ScriptSpaceWriteCommand: public script_space_module::ScriptSpaceWrite_Comm
public:
static void execute(ZscriptCommandContext<ZP> ctx) {
uint16_t spaceIndex;
if (!ctx.getField(ReqScriptSpaceId__P, &spaceIndex)) {
ctx.status(ResponseStatus::MISSING_KEY);
return;
} else if (spaceIndex >= Zscript<ZP>::zscript.getScriptSpaceCount()) {
ctx.status(ResponseStatus::VALUE_OUT_OF_RANGE);
if (!ctx.getReqdFieldCheckLimit(ReqScriptSpaceId__P, Zscript<ZP>::zscript.getScriptSpaceCount(), &spaceIndex)) {
return;
}

Expand Down

0 comments on commit f2331f6

Please sign in to comment.