Skip to content

Commit d30b73a

Browse files
Switch CodeQL to supported compiler
Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
1 parent 05107a7 commit d30b73a

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The technical progression and current state of the NLAP implementation comprise
6363
5. **C++23 Parsing Library:** Engineered a specialized, performance- and heap-optimized C++23 validation library for low-level HTTP/1.1 parsing and message generation.
6464
6. **Architectural Refactoring:** Executed a comprehensive code-base refactoring based on the empirical performance metrics gathered from the initial reference implementations.
6565
7. **Schema Implementation:** Developed the comprehensive structural boundaries for all NLAP protocol subtypes, formalized through complete Document Type Definitions (DTD) and YANG modeling layouts compiled with AI assistance.
66-
8. **Zero-Copy XML Parsing Engine:** Implemented a memory-optimized XML parsing layer utilizing C++23 features (`std::generator`) and non-allocating string views (`std::string_view`) to minimize data-handling overhead, developed with AI assistance.
66+
8. **Zero-Copy XML Parsing Engine:** Implemented a memory-optimized XML parsing layer utilizing non-allocating string views (`std::string_view`) and lightweight iteration helpers to minimize data-handling overhead, developed with AI assistance.
6767

6868
# 5. Working Components
6969

‎lib/xml/xmlparser.cpp‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <algorithm>
77
#include <atomic>
8-
#include <generator>
98
#include <cstring>
109
#include <memory>
1110
#include <utility>
@@ -69,13 +68,14 @@ std::string getElementText(DOMElement* Element)
6968
return trimCopy(Value);
7069
}
7170

72-
std::generator<DOMElement*> iterateElementChildren(DOMElement* Parent)
71+
template <typename Callback>
72+
void forEachElementChild(DOMElement* Parent, Callback&& Visitor)
7373
{
7474
DOMNodeList* Children = Parent->getChildNodes();
7575
for (XMLSize_t Index = 0; Index < Children->getLength(); ++Index) {
7676
DOMNode* Child = Children->item(Index);
7777
if (Child->getNodeType() == DOMNode::ELEMENT_NODE) {
78-
co_yield static_cast<DOMElement*>(Child);
78+
Visitor(static_cast<DOMElement*>(Child));
7979
}
8080
}
8181
}
@@ -85,7 +85,8 @@ struct MessageSlice
8585
std::string_view Slice;
8686
};
8787

88-
std::generator<MessageSlice> splitMessages(std::string_view Input, bool& FramingError)
88+
template <typename Callback>
89+
void splitMessages(std::string_view Input, bool& FramingError, Callback&& Visitor)
8990
{
9091
std::size_t Cursor = 0;
9192
std::size_t LastEnd = std::string_view::npos;
@@ -98,7 +99,7 @@ std::generator<MessageSlice> splitMessages(std::string_view Input, bool& Framing
9899

99100
if (LastEnd != std::string_view::npos && Start != LastEnd) {
100101
FramingError = true;
101-
co_return;
102+
return;
102103
}
103104

104105
const std::size_t End = Input.find(NLAP_XML_END_MARKER, Start);
@@ -107,7 +108,9 @@ std::generator<MessageSlice> splitMessages(std::string_view Input, bool& Framing
107108
}
108109

109110
const std::size_t MessageEnd = End + NLAP_XML_END_MARKER.size();
110-
co_yield MessageSlice{Input.substr(Start, MessageEnd - Start)};
111+
if (!Visitor(MessageSlice{Input.substr(Start, MessageEnd - Start)})) {
112+
return;
113+
}
111114

112115
Cursor = MessageEnd;
113116
LastEnd = MessageEnd;
@@ -197,12 +200,12 @@ void populateTree(DOMElement* Element, XMLNode& Node, std::string_view RawMessag
197200
{
198201
bool HasElementChildren = false;
199202

200-
for (DOMElement* Child : iterateElementChildren(Element)) {
203+
forEachElementChild(Element, [&](DOMElement* Child) {
201204
HasElementChildren = true;
202205
const std::string ChildName = transcodeXMLCh(Child->getTagName());
203206
XMLNode& ChildNode = Node[ChildName];
204207
populateTree(Child, ChildNode, RawMessage, SearchOffset);
205-
}
208+
});
206209

207210
if (HasElementChildren) {
208211
return;
@@ -297,11 +300,11 @@ uint16_t parseMessage(
297300
XMLNode& RootNode = OutputTree[RootName];
298301

299302
std::size_t SearchOffset = 0;
300-
for (DOMElement* Child : iterateElementChildren(Root)) {
303+
forEachElementChild(Root, [&](DOMElement* Child) {
301304
const std::string ChildName = transcodeXMLCh(Child->getTagName());
302305
XMLNode& ChildNode = RootNode[ChildName];
303306
populateTree(Child, ChildNode, RawMessage, SearchOffset);
304-
}
307+
});
305308

306309
return 0;
307310
}
@@ -372,17 +375,22 @@ ParseResult_t XMLParser::parse(char* InputBuffer) const
372375
}
373376

374377
bool FramingError = false;
375-
for (const MessageSlice& Slice : splitMessages(InputBufferSV, FramingError)) {
378+
splitMessages(InputBufferSV, FramingError, [&](const MessageSlice& Slice) {
376379
ResultTree_t Tree;
377380
const uint16_t MessageError = parseMessage(_GrammarPool, Slice.Slice, Tree);
378381

379382
if (MessageError != 0) {
380383
Result.ErrorCode = MessageError;
381384
Result.Results.clear();
382-
return Result;
385+
return false;
383386
}
384387

385388
Result.Results.push_back(std::move(Tree));
389+
return true;
390+
});
391+
392+
if (Result.ErrorCode != 0) {
393+
return Result;
386394
}
387395

388396
if (FramingError) {

0 commit comments

Comments
 (0)