From 9e23016dd4422a47ea7d406eb4a08338940f91c9 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 27 Aug 2026 02:16:33 -0400 Subject: [PATCH] [Perf] (ShaderTranspiler): memchr the mid-line #version scan and gate it on an accepted directive --- .../ShaderTranspiler/ShaderSourceProcessor.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp b/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp index 2d975531..4d60829a 100644 --- a/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp +++ b/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp @@ -335,10 +335,15 @@ namespace { // #version splice the second into the tail of the first. Only an EXACT repeat of // the directive already accepted is recognized here; see // BlankRedundantVersionDirectives for why that one is tolerated and nothing else. - for (SizeT scan = probe; scan < lineEnd; ++scan) { - if (code[scan] != '#') continue; - recordIfRedundant(scan, lineEnd); - break; + // + // Gated on a directive having been accepted already, so an ordinary shader - which + // has none of these - pays one memchr per line past its #version line and nothing + // before it. + if (info.hasValidVersionDirective) { + const SizeT hashPos = code.find('#', probe); + if (hashPos != MobileGL::String::npos && hashPos < lineEnd) { + recordIfRedundant(hashPos, lineEnd); + } } } else { const SizeT directiveStart = probe;