Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShaderCodeCursor. Optimization of lines parsing #13935

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions packages/dev/core/src/Engines/Processors/shaderCodeCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,57 @@ export class ShaderCodeCursor {
this._lines.length = 0;

for (const line of value) {
// Skip empty lines
if (!line || line === "\r") {
continue;
}

// Prevent removing line break in macros.
if (line[0] === "#") {
this._lines.push(line);
continue;
}

// Do not split single line comments
if (line.trim().startsWith("//")) {
const trimmedLine = line.trim();

if (!trimmedLine) {
continue;
}

if (trimmedLine.startsWith("//")) {
this._lines.push(line);
continue;
}

const split = line.split(";");
// Work with semicolon in the line
const semicolonIndex = trimmedLine.indexOf(";");

for (let index = 0; index < split.length; index++) {
let subLine = split[index];
subLine = subLine.trim();
if (semicolonIndex === -1) {
// No semicolon in the line
this._lines.push(trimmedLine);
} else if (semicolonIndex === trimmedLine.length - 1) {
// Semicolon at the end of the line
this._lines.push(trimmedLine);
} else {
// Semicolon in the middle of the line
const split = line.split(";");

if (!subLine) {
continue;
}
for (let index = 0; index < split.length; index++) {
let subLine = split[index];

if (!subLine) {
continue;
}

this._lines.push(subLine + (index !== split.length - 1 ? ";" : ""));
subLine = subLine.trim();

if (!subLine) {
continue;
}

this._lines.push(subLine + (index !== split.length - 1 ? ";" : ""));
}
}
}
}
Expand Down