perf(source): index original line boundaries once

Avoid scanning the remaining original text for every heading on a long raw HTML line; verify 300 distinct same-line anchors. Record full native/published/installed vim acceptance while retaining full source synchronization scope.

Refs #10

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: James Maes <jmaes@dmdbrands.com>
This commit is contained in:
James MaesandCodex committed 2026-10-10 23:53:48 -05:00
1 parent a0d8fe73aa
commit b0f3b8638f
5 files changed
+49 -6

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
Build a Windows counterpart to [Darin Kelkhoff's markdownViewr](https://github.com/darinkelkhoff/markdownViewr), using the KofTwentyTwo AppKit foundations and standards. The agreed display name is MarkdownViewr, repository MarkdownViewr.Windows, and permanent application ID markdownviewr-windows.
The first reader implementation opens Markdown with a Windows picker or literal launch argument, renders sanitized GFM and supports bounded local images, manual reload and automatic saves with relative scroll preservation. The original 20 document themes and persistent palette selection are implemented. Hosted reader/live-reload/theme selection and both installed update channels passed on 77dd04d. Editable custom themes, color/code-font/CSS controls and restoration are implemented; their dialog/browser acceptance passed in CI 38102867556. Frontmatter, resizable outline/depth/jump/section controls and literal source visibility/reload/physical resize passed CI 38106991467: 34 native/UI and published tests, 33 per installed channel, no skips. Paired browser/source find, repeated local-fragment reveal and configured editor launch passed CI 38110726381: 41 native/published tests and 40 per installed channel, no skips. Vim navigation is implemented with 239 core tests/100% lines; its new physical-key acceptance remains pending. The full feature list below remains the target; the first reader is not a completed port.
The first reader implementation opens Markdown with a Windows picker or literal launch argument, renders sanitized GFM and supports bounded local images, manual reload and automatic saves with relative scroll preservation. The original 20 document themes and persistent palette selection are implemented. Hosted reader/live-reload/theme selection and both installed update channels passed on 77dd04d. Editable custom themes, color/code-font/CSS controls and restoration are implemented; their dialog/browser acceptance passed in CI 38102867556. Frontmatter, resizable outline/depth/jump/section controls and literal source visibility/reload/physical resize passed CI 38106991467: 34 native/UI and published tests, 33 per installed channel, no skips. Paired browser/source find, repeated local-fragment reveal and configured editor launch passed CI 38110726381: 41 native/published tests and 40 per installed channel, no skips. Vim navigation passed CI 38112298176: 44 native/published tests and 43 per installed channel, zero skips. Parser-derived source positions are implemented with 255 core tests/100% lines; source heading/scroll/collapse UI synchronization remains pending. The full feature list below remains the target; the first reader is not a completed port.
## Reference and feature scope
+18
View File
@@ -330,3 +330,21 @@ Raw line lookup is indexed rather than rescanning all lines for each heading.
snapshot and public renderer policy remain unchanged. Full scroll/heading/collapse
source UI remains unimplemented, not replaced by this foundation. No GUI input,
Azure attempt, merge/tag/release or claim of production signing.
## Verified vim channels and indexed source line ends
6bf125d / CI 38112298176 is fully SUCCESS. Retained TRX proves native/published
44/44 and installed stable/dev 43/43 each, zero failures/skips. Evidence retained
in artifacts/vim-verified-installed-38112298176, native and installed job logs.
Four payload gates verify 536 files per payload; update probes apply/restart both
channels. Fixtures remain synthetic/unsigned and do not prove production signing.
All exact prior producers are terminal before this source increment's push.
Local signed source-provenance a0d8fe7 has a further tested indexed-line-end fix:
255 core tests/100% lines and zero-warning build/format pass. A 300-heading raw
single-line regression verifies distinct offsets with one shared line end. Global
line ends are indexed once; per-heading lookup is logarithmic. This avoids a
quadratic full-remainder scan for adversarial long raw HTML lines. The source
snapshot remains immutable; no new capability/dependency is introduced. Update
PRODUCT/TODO with actual vim proof; source synchronization UI stays pending and
full scope remains active. No local GUI input, Azure attempt, merge/tag/release.
+1 -1
View File
@@ -24,7 +24,7 @@
- [x] Implement paired native browser/source find with bounded literal terms, shared counts, wraparound and reload guards (issue #10).
- [x] Verify paired find and repeated local-fragment reveal on 5a9af63: 41 native/published and 40 per installed channel, zero skips.
- [x] Implement all required vim reading/find/heading commands, timed prefixes and native focus/modifier guards (issue #10).
- [ ] Verify physical vim browser viewport, collapsed-heading and query-typing acceptance in native/published/installed builds.
- [x] Verify physical vim viewport, collapsed-heading and query-typing acceptance on 6bf125d: CI 38112298176, 44 native/published and 43 per installed channel, zero skips.
- [x] Map sanitized surviving headings to original parser-derived source offsets (Setext/fences/raw HTML/frontmatter/duplicates); source UI synchronization remains pending.
- [ ] Add synchronized source headings/scroll/collapse (issue #10); audit find/source collapse parity against the pinned reference.
- [x] Implement and core-test hidden/metadata/Markdown frontmatter modes, with persisted native controls and attribution.
@@ -18,7 +18,7 @@ namespace MarkdownViewr.Windows.Core.Documents;
/// <summary>Carries parser provenance through sanitation using a fresh private attribute removed before presentation.</summary>
internal sealed class DocumentSourceMap
{
private readonly string _source;
private readonly int[] _lineEnds;
private readonly Dictionary<string, (int Start, int End)> _positions = new(StringComparer.Ordinal);
@@ -27,7 +27,15 @@ internal sealed class DocumentSourceMap
public DocumentSourceMap(string source)
{
ArgumentNullException.ThrowIfNull(source);
_source = source;
var ends = new List<int>();
int start = 0;
while(source.IndexOf('\n', start) is int end && end >= 0)
{
ends.Add(end);
start = end + 1;
}
ends.Add(source.Length);
_lineEnds = ends.ToArray();
AttributeName = "data-mv-source-" + Guid.NewGuid().ToString("N");
}
@@ -86,8 +94,8 @@ internal sealed class DocumentSourceMap
/// <summary>Raw heading markup stays on its original source line; the canonical snapshot is never rewritten.</summary>
private int EndOfLine(int start)
{
int end = _source.IndexOf('\n', start);
return end >= 0 ? end : _source.Length;
int index = Array.BinarySearch(_lineEnds, start);
return _lineEnds[index >= 0 ? index : ~index];
}
@@ -101,6 +101,23 @@ public sealed class DocumentSourceHeadingTests
/// <summary>Many raw headings on one line share one bounded line end without rescanning its entire remaining text per heading.</summary>
[Fact]
public void Create_ManyRawHeadingsOnOneLine_PreservesDistinctOffsets()
{
string source = string.Concat(Enumerable.Repeat("<h2>Same</h2>", 300));
var outline = new DocumentOutline(source);
Assert.Equal(300, outline.SourceHeadings.Count);
for(int index = 0; index < outline.SourceHeadings.Count; index++)
{
Assert.Equal(index * "<h2>Same</h2>".Length, outline.SourceHeadings[index].Start);
Assert.Equal(source.Length, outline.SourceHeadings[index].End);
}
Assert.DoesNotContain("data-mv-source-", outline.Html, StringComparison.OrdinalIgnoreCase);
}
/// <summary>A mapped render still rejects null, oversized content and corrupt frontmatter modes before use.</summary>
[Fact]
public void Create_InvalidInput_PreservesRenderingLimits()