mirror of https://gitlab.com/basile.b/dexed.git
optimized lfm script creation
- the final string size can be efficiently guessed and reserved - use cached memver named instead of calling to for each item member
This commit is contained in:
parent
945212f4c9
commit
7c871076d4
|
|
@ -100,13 +100,13 @@ private struct TodoItem
|
||||||
* Params:
|
* Params:
|
||||||
* LfmString = the string containing the LFM script.
|
* LfmString = the string containing the LFM script.
|
||||||
*/
|
*/
|
||||||
@safe public void serialize(ref string LfmString)
|
@safe public void serialize(ref Appender!string lfmApp)
|
||||||
{
|
{
|
||||||
LfmString ~= " \r\n item\r\n";
|
lfmApp.put(" \r item\r");
|
||||||
foreach(member; EnumMembers!TodoField)
|
foreach(member; EnumMembers!TodoField)
|
||||||
if (fFields[member].length)
|
if (fFields[member].length)
|
||||||
LfmString ~= format(" %s = '%s'\r\n", to!string(member), fFields[member]);
|
lfmApp.put(format(" %s = '%s'\r", fFieldNames[member], fFields[member]));
|
||||||
LfmString ~= " end";
|
lfmApp.put(" end");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ private alias TodoItems = TodoItem * [];
|
||||||
void main(string[] args)
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
string[] files = args[1..$];
|
string[] files = args[1..$];
|
||||||
string LfmString;
|
Appender!string lfmApp;
|
||||||
TodoItems todoItems;
|
TodoItems todoItems;
|
||||||
|
|
||||||
foreach(f; files)
|
foreach(f; files)
|
||||||
|
|
@ -140,13 +140,18 @@ void main(string[] args)
|
||||||
foreach(tok; lexer) token2TodoItem(tok, f, todoItems);
|
foreach(tok; lexer) token2TodoItem(tok, f, todoItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// efficient appending if the item text ~ fields is about 100 chars
|
||||||
|
lfmApp.reserve(todoItems.length * 128 + 64);
|
||||||
|
|
||||||
// serialize the items using the pascal component streaming text format
|
// serialize the items using the pascal component streaming text format
|
||||||
foreach(todoItem; todoItems) todoItem.serialize(LfmString);
|
lfmApp.put("object TTodoItems\r items = <");
|
||||||
|
foreach(todoItem; todoItems) todoItem.serialize(lfmApp);
|
||||||
//TODO: NEVER call writeln() in this program otherwise the widget cant interpret the output as LFM
|
lfmApp.put(">\rend\r\n");
|
||||||
|
|
||||||
// the widget has the LFM script in the output
|
// the widget has the LFM script in the output
|
||||||
if (LfmString.length) writefln("object TTodoItems\r\n items = <%s>\r\nend\r\n", LfmString);
|
write(lfmApp.data);
|
||||||
|
|
||||||
|
// TODO: NEVER call writeln() in this program otherwise the widget cant interpret the output
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to transforms a Token into a a TODO item
|
/// Try to transforms a Token into a a TODO item
|
||||||
|
|
@ -216,7 +221,7 @@ void main(string[] args)
|
||||||
todoItems ~= new TodoItem(fname, to!string(atok.line), content, c, a, p, s);
|
todoItems ~= new TodoItem(fname, to!string(atok.line), content, c, a, p, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// samples for testing the program as a runnable module with <CFF>
|
// samples for testing the program as a runnable ('Compile and runfile ...') with '<CFF>'
|
||||||
|
|
||||||
// fixme-p8: fixme also handled
|
// fixme-p8: fixme also handled
|
||||||
// TODO-cINVALID_because_no_content:
|
// TODO-cINVALID_because_no_content:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue