mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
Remove now-redundant MmappedContent struct
This commit is contained in:
@@ -46,6 +46,14 @@ struct ContentSpan {
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ViewedContent {
|
||||||
|
ContentSpan span;
|
||||||
|
size_t offset = 0;
|
||||||
|
|
||||||
|
ViewedContent(ContentSpan const &span_) : span(span_) {}
|
||||||
|
ViewedContent(std::shared_ptr<char[]> ptr, size_t size) : span({.ptr = ptr, .size = size}) {}
|
||||||
|
};
|
||||||
|
|
||||||
struct BufferedContent {
|
struct BufferedContent {
|
||||||
int fd;
|
int fd;
|
||||||
size_t index = 0; // Read index into the buffer
|
size_t index = 0; // Read index into the buffer
|
||||||
@@ -56,20 +64,6 @@ struct BufferedContent {
|
|||||||
~BufferedContent();
|
~BufferedContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MmappedContent {
|
|
||||||
ContentSpan span;
|
|
||||||
size_t offset = 0;
|
|
||||||
|
|
||||||
MmappedContent(std::shared_ptr<char[]> ptr, size_t size) : span({.ptr = ptr, .size = size}) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ViewedContent {
|
|
||||||
ContentSpan span;
|
|
||||||
size_t offset = 0;
|
|
||||||
|
|
||||||
ViewedContent(ContentSpan const &span_) : span(span_) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LexerState {
|
struct LexerState {
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
@@ -92,7 +86,7 @@ struct LexerState {
|
|||||||
bool expandStrings;
|
bool expandStrings;
|
||||||
std::deque<Expansion> expansions; // Front is the innermost current expansion
|
std::deque<Expansion> expansions; // Front is the innermost current expansion
|
||||||
|
|
||||||
std::variant<std::monostate, MmappedContent, ViewedContent, BufferedContent> content;
|
std::variant<std::monostate, ViewedContent, BufferedContent> content;
|
||||||
|
|
||||||
~LexerState();
|
~LexerState();
|
||||||
|
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ bool LexerState::setFileAsNextState(std::string const &filePath, bool updateStat
|
|||||||
|
|
||||||
if (mappingAddr != MAP_FAILED) {
|
if (mappingAddr != MAP_FAILED) {
|
||||||
close(fd);
|
close(fd);
|
||||||
content.emplace<MmappedContent>(
|
content.emplace<ViewedContent>(
|
||||||
std::shared_ptr<char[]>(
|
std::shared_ptr<char[]>(
|
||||||
(char *)mappingAddr, MunmapDeleter((size_t)statBuf.st_size)
|
(char *)mappingAddr, MunmapDeleter((size_t)statBuf.st_size)
|
||||||
),
|
),
|
||||||
@@ -468,9 +468,7 @@ void LexerState::setViewAsNextState(char const *name, ContentSpan const &span, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lexer_RestartRept(uint32_t lineNo) {
|
void lexer_RestartRept(uint32_t lineNo) {
|
||||||
if (auto *mmap = std::get_if<MmappedContent>(&lexerState->content); mmap) {
|
if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
||||||
mmap->offset = 0;
|
|
||||||
} else if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
|
||||||
view->offset = 0;
|
view->offset = 0;
|
||||||
}
|
}
|
||||||
lexerState->clear(lineNo);
|
lexerState->clear(lineNo);
|
||||||
@@ -672,11 +670,7 @@ static int peekInternal(uint8_t distance) {
|
|||||||
LEXER_BUF_SIZE
|
LEXER_BUF_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (auto *mmap = std::get_if<MmappedContent>(&lexerState->content); mmap) {
|
if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
||||||
if (size_t idx = mmap->offset + distance; idx < mmap->span.size)
|
|
||||||
return (uint8_t)mmap->span.ptr[idx];
|
|
||||||
return EOF;
|
|
||||||
} else if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
|
||||||
if (size_t idx = view->offset + distance; idx < view->span.size)
|
if (size_t idx = view->offset + distance; idx < view->span.size)
|
||||||
return (uint8_t)view->span.ptr[idx];
|
return (uint8_t)view->span.ptr[idx];
|
||||||
return EOF;
|
return EOF;
|
||||||
@@ -796,9 +790,7 @@ restart:
|
|||||||
} else {
|
} else {
|
||||||
// Advance within the file contents
|
// Advance within the file contents
|
||||||
lexerState->colNo++;
|
lexerState->colNo++;
|
||||||
if (auto *mmap = std::get_if<MmappedContent>(&lexerState->content); mmap) {
|
if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
||||||
mmap->offset++;
|
|
||||||
} else if (auto *view = std::get_if<ViewedContent>(&lexerState->content); view) {
|
|
||||||
view->offset++;
|
view->offset++;
|
||||||
} else {
|
} else {
|
||||||
assert(std::holds_alternative<BufferedContent>(lexerState->content));
|
assert(std::holds_alternative<BufferedContent>(lexerState->content));
|
||||||
@@ -2179,17 +2171,22 @@ static Capture startCapture() {
|
|||||||
lexerState->captureSize = 0;
|
lexerState->captureSize = 0;
|
||||||
|
|
||||||
uint32_t lineNo = lexer_GetLineNo();
|
uint32_t lineNo = lexer_GetLineNo();
|
||||||
if (auto *mmap = std::get_if<MmappedContent>(&lexerState->content);
|
if (auto *view = std::get_if<ViewedContent>(&lexerState->content);
|
||||||
mmap && lexerState->expansions.empty()) {
|
|
||||||
return {.lineNo = lineNo, .span = {.ptr = std::shared_ptr<char[]>(mmap->span.ptr, &mmap->span.ptr[mmap->offset]), .size = 0}};
|
|
||||||
} else if (auto *view = std::get_if<ViewedContent>(&lexerState->content);
|
|
||||||
view && lexerState->expansions.empty()) {
|
view && lexerState->expansions.empty()) {
|
||||||
return {.lineNo = lineNo, .span = {.ptr = std::shared_ptr<char[]>(view->span.ptr, &view->span.ptr[view->offset]), .size = 0}};
|
return {
|
||||||
|
.lineNo = lineNo,
|
||||||
|
.span = {
|
||||||
|
.ptr = std::shared_ptr<char[]>(view->span.ptr, &view->span.ptr[view->offset]),
|
||||||
|
.size = 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
assert(lexerState->captureBuf == nullptr);
|
assert(lexerState->captureBuf == nullptr);
|
||||||
lexerState->captureBuf = std::make_shared<std::vector<char>>();
|
lexerState->captureBuf = std::make_shared<std::vector<char>>();
|
||||||
// `.span.ptr == nullptr`; indicates to retrieve the capture buffer when done capturing
|
// `.span.ptr == nullptr`; indicates to retrieve the capture buffer when done capturing
|
||||||
return {.lineNo = lineNo, .span = {.ptr = nullptr, .size = 0}};
|
return {
|
||||||
|
.lineNo = lineNo, .span = {.ptr = nullptr, .size = 0}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user