Skip to content

Print LOC and SLOC as part of the build process#22

Merged
frostney merged 2 commits into
mainfrom
feat-print-loc-sloc
Feb 20, 2026
Merged

Print LOC and SLOC as part of the build process#22
frostney merged 2 commits into
mainfrom
feat-print-loc-sloc

Conversation

@frostney
Copy link
Copy Markdown
Owner

@frostney frostney commented Feb 20, 2026

Summary by CodeRabbit

  • New Features
    • Build now displays aggregated source-code statistics at startup, summarizing total lines and source lines across supported file types.
    • Numbers in the summary are formatted for readability, giving a clearer view of codebase size and composition.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds source-statistics reporting to build.pas: line-counting and formatting helpers plus a PrintSourceStats procedure, and invokes it during the Build initialization (after PrintVersion) to emit aggregated LOC/SLOC for Pascal-related source files.

Changes

Cohort / File(s) Summary
Source metrics & startup hook
build.pas
Adds StripBlockComments(var AText: string; var AInBlock: Boolean), CountLines(const AFileName: string; out ALOC, ASLOC: Integer), FormatNumber(const AValue: Integer): string, and PrintSourceStats. Calls PrintSourceStats from Build (after PrintVersion) to print aggregated LOC/SLOC for .pas, .dpr, and .inc files.

Sequence Diagram(s)

sequenceDiagram
    participant Build as Build()
    participant Ver as PrintVersion()
    participant Stats as PrintSourceStats()
    participant FS as FileSystem
    participant Console as Console

    Build->>Ver: call PrintVersion
    Ver-->>Build: returned
    Build->>Stats: call PrintSourceStats
    Stats->>FS: enumerate source files (.pas/.dpr/.inc)
    FS-->>Stats: file list
    loop per file
        Stats->>FS: read file contents
        FS-->>Stats: file text
        Stats->>Stats: StripBlockComments / CountLines
        Stats->>Console: aggregate & format numbers
    end
    Stats-->>Build: done
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Counting hops on every line,

I sniff comments, skip each sign,
LOC and SLOC, neat and bright,
I tally bytes by morning light,
A rabbit's cheer for build.pas tonight! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Print LOC and SLOC as part of the build process' directly and clearly describes the main changes: adding source code statistics (LOC/SLOC) printing to the build initialization process.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-print-loc-sloc

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@build.pas`:
- Around line 112-126: The parameter AValue in function FormatNumber is not
modified; change its declaration to a const parameter to follow guidelines by
updating the function signature from "function FormatNumber(AValue: Integer):
string;" to use "const AValue: Integer" (keep the body unchanged), ensuring
callers are unaffected while signaling immutability and enabling potential
compiler optimizations.
- Around line 51-106: CountLines currently treats inline or same-line block
comments like '{ ... }' or '(* ... *)' as code; update the per-line handling so
Trimmed is stripped of any inline block comments before deciding SLOC or
toggling InBlock: when not InBlock, scan Trimmed for '{' or '(*' and if a
matching '}' or '*)' exists on the same line remove the entire comment span and
re-evaluate the line (repeat if multiple comments); if an opening '{' or '(*'
has no closing on the same line set InBlock := True and delete from the opening
to end of line (so code before the comment counts); when InBlock is true
continue scanning for closing tokens ('}' or '*)'), remove up through the close,
set InBlock := False, then re-trim and re-evaluate the remaining text for more
comments or code; apply these changes inside CountLines using the existing
variables Trimmed, InBlock, ClosePos, Pos, Delete, Trim, Inc(ASLOC) so
subsequent lines are counted correctly.

Comment thread build.pas
Comment thread build.pas Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 20, 2026

Benchmark Results

172 benchmarks · 🟢 36 improved · 136 unchanged · avg +4.6%

arrays.js — 12 unchanged · avg +1.1%
Benchmark Base (ops/sec) PR (ops/sec) Change
Array.from length 100 4,795 4,835 +0.8%
Array.from 10 elements 124,836 127,067 +1.8%
Array.of 10 elements 151,578 155,618 +2.7%
spread into new array 159,806 161,670 +1.2%
map over 50 elements 4,634 4,678 +0.9%
filter over 50 elements 4,234 4,392 +3.7%
reduce sum 50 elements 4,481 4,530 +1.1%
forEach over 50 elements 4,114 4,127 +0.3%
find in 50 elements 4,670 4,880 +4.5%
sort 20 elements 4,087 4,050 -0.9%
flat nested array 68,400 69,195 +1.2%
flatMap 35,760 34,463 -3.6%
classes.js — 15 unchanged · avg +4.4%
Benchmark Base (ops/sec) PR (ops/sec) Change
simple class new 66,871 68,672 +2.7%
class with defaults 51,549 53,226 +3.3%
50 instances via Array.from 2,416 2,499 +3.4%
instance method call 32,074 33,191 +3.5%
static method call 53,116 54,750 +3.1%
single-level inheritance 26,340 27,295 +3.6%
two-level inheritance 23,955 24,987 +4.3%
private field access 33,826 35,416 +4.7%
private methods 39,524 41,292 +4.5%
getter/setter access 35,298 37,175 +5.3%
static getter read 65,136 68,496 +5.2%
static getter/setter pair 45,613 48,418 +6.2%
inherited static getter 39,414 41,492 +5.3%
inherited static setter 41,904 44,216 +5.5%
inherited static getter with this binding 33,122 34,903 +5.4%
closures.js — 11 unchanged · avg +2.5%
Benchmark Base (ops/sec) PR (ops/sec) Change
closure over single variable 55,488 56,916 +2.6%
closure over multiple variables 54,955 56,713 +3.2%
nested closures 60,269 62,275 +3.3%
function as argument 42,314 43,052 +1.7%
function returning function 55,812 57,383 +2.8%
compose two functions 34,663 35,433 +2.2%
fn.call 83,649 85,935 +2.7%
fn.apply 59,167 59,981 +1.4%
fn.bind 70,250 72,190 +2.8%
recursive sum to 50 4,894 4,905 +0.2%
recursive tree traversal 8,500 8,861 +4.2%
collections.js — 12 unchanged · avg +2.2%
Benchmark Base (ops/sec) PR (ops/sec) Change
add 50 elements 3,101 3,143 +1.4%
has lookup (50 elements) 5,248 5,329 +1.5%
delete elements 13,845 14,064 +1.6%
forEach iteration 3,029 3,054 +0.8%
spread to array 6,103 6,174 +1.2%
deduplicate array 23,762 24,254 +2.1%
set 50 entries 2,452 2,530 +3.2%
get lookup (50 entries) 2,980 3,045 +2.2%
has check 2,984 3,093 +3.6%
delete entries 7,839 8,052 +2.7%
forEach iteration 2,087 2,142 +2.6%
keys/values/entries 2,355 2,442 +3.7%
destructuring.js — 🟢 2 improved, 12 unchanged · avg +3.1%
Benchmark Base (ops/sec) PR (ops/sec) Change
simple array destructuring 174,755 173,235 -0.9%
with rest element 130,225 131,671 +1.1%
with defaults 175,641 176,729 +0.6%
skip elements 191,025 190,110 -0.5%
nested array destructuring 100,746 100,379 -0.4%
swap variables 203,431 210,815 +3.6%
simple object destructuring 135,069 137,990 +2.2%
with defaults 159,789 163,452 +2.3%
with renaming 155,832 160,326 +2.9%
nested object destructuring 78,787 83,941 +6.5%
rest properties 82,731 88,235 +6.7%
object parameter 48,923 53,130 🟢 +8.6%
array parameter 63,517 64,947 +2.3%
mixed destructuring in map 5,603 6,052 🟢 +8.0%
fibonacci.js — 6 unchanged · avg +3.1%
Benchmark Base (ops/sec) PR (ops/sec) Change
recursive fib(15) 133 138 +4.1%
recursive fib(20) 12 12 -0.2%
iterative fib(20) via reduce 6,703 6,876 +2.6%
iterator fib(20) 3,726 3,898 +4.6%
iterator fib(20) via Iterator.from + take 3,834 3,996 +4.2%
iterator fib(20) last value via reduce 3,190 3,292 +3.2%
iterators.js — 🟢 3 improved, 17 unchanged · avg +5.5%
Benchmark Base (ops/sec) PR (ops/sec) Change
Iterator.from({next}).toArray() — 20 elements 5,059 5,242 +3.6%
Iterator.from({next}).toArray() — 50 elements 2,156 2,258 +4.7%
spread pre-wrapped iterator — 20 elements 5,058 5,241 +3.6%
Iterator.from({next}).forEach — 50 elements 1,603 1,684 +5.1%
Iterator.from({next}).reduce — 50 elements 1,651 1,726 +4.5%
wrap array iterator 30,025 31,275 +4.2%
wrap plain {next()} object 3,469 3,692 +6.4%
map + toArray (50 elements) 1,395 1,489 +6.7%
filter + toArray (50 elements) 1,493 1,563 +4.7%
take(10) + toArray (50 element source) 8,001 8,314 +3.9%
drop(40) + toArray (50 element source) 2,087 2,217 +6.2%
chained map + filter + take (100 element source) 2,449 2,588 +5.7%
some + every (50 elements) 923 1,001 🟢 +8.5%
find (50 elements) 2,012 2,204 🟢 +9.6%
array.values().map().filter().toArray() 1,452 1,512 +4.1%
array.values().take(5).toArray() 6,868 7,382 🟢 +7.5%
array.values().drop(45).toArray() 4,299 4,494 +4.5%
map.entries() chained helpers 1,888 1,984 +5.1%
set.values() chained helpers 2,984 3,155 +5.8%
string iterator map + toArray 4,079 4,311 +5.7%
json.js — 🟢 13 improved, 7 unchanged · avg +7.3%
Benchmark Base (ops/sec) PR (ops/sec) Change
parse simple object 108,497 116,383 🟢 +7.3%
parse nested object 69,545 74,715 🟢 +7.4%
parse array of objects 39,246 41,287 +5.2%
parse large flat object 34,326 35,493 +3.4%
parse mixed types 50,907 53,545 +5.2%
stringify simple object 96,948 103,532 +6.8%
stringify nested object 55,844 59,517 +6.6%
stringify array of objects 10,437 11,307 🟢 +8.3%
stringify mixed types 45,760 49,505 🟢 +8.2%
reviver doubles numbers 21,463 23,228 🟢 +8.2%
reviver filters properties 20,334 21,426 +5.4%
reviver on nested object 25,475 27,636 🟢 +8.5%
reviver on array 14,810 15,589 +5.3%
replacer function doubles numbers 20,401 21,912 🟢 +7.4%
replacer function excludes properties 26,951 29,046 🟢 +7.8%
array replacer (allowlist) 56,773 62,373 🟢 +9.9%
stringify with 2-space indent 54,280 58,785 🟢 +8.3%
stringify with tab indent 54,594 59,558 🟢 +9.1%
parse then stringify 33,948 36,598 🟢 +7.8%
stringify then parse 11,521 12,718 🟢 +10.4%
jsx.jsx — 🟢 11 improved, 10 unchanged · avg +7.2%
Benchmark Base (ops/sec) PR (ops/sec) Change
simple element 107,938 113,893 +5.5%
self-closing element 111,109 117,411 +5.7%
element with string attribute 92,073 98,413 +6.9%
element with multiple attributes 79,708 86,173 🟢 +8.1%
element with expression attribute 83,036 89,607 🟢 +7.9%
text child 106,272 114,613 🟢 +7.8%
expression child 102,288 109,418 +7.0%
mixed text and expression 98,538 105,977 🟢 +7.5%
nested elements (3 levels) 41,498 44,493 🟢 +7.2%
sibling children 31,060 33,339 🟢 +7.3%
component element 78,211 83,269 +6.5%
component with children 48,572 52,150 🟢 +7.4%
dotted component 65,920 70,326 +6.7%
empty fragment 104,778 110,701 +5.7%
fragment with children 30,276 32,588 🟢 +7.6%
spread attributes 58,890 64,679 🟢 +9.8%
spread with overrides 51,193 56,277 🟢 +9.9%
shorthand props 78,331 83,533 +6.6%
nav bar structure 14,830 15,713 +6.0%
card component tree 17,373 18,664 🟢 +7.4%
10 list items via Array.from 7,538 8,002 +6.2%
numbers.js — 11 unchanged · avg +3.1%
Benchmark Base (ops/sec) PR (ops/sec) Change
integer arithmetic 174,742 178,279 +2.0%
floating point arithmetic 197,688 204,891 +3.6%
number coercion 103,796 107,205 +3.3%
toFixed 70,025 72,683 +3.8%
toString 94,336 98,050 +3.9%
valueOf 123,673 126,873 +2.6%
toPrecision 88,456 92,909 +5.0%
Number.isNaN 156,274 161,238 +3.2%
Number.isFinite 150,024 152,951 +2.0%
Number.isInteger 153,971 155,950 +1.3%
Number.parseInt and parseFloat 140,945 144,985 +2.9%
objects.js — 🟢 2 improved, 5 unchanged · avg +6.2%
Benchmark Base (ops/sec) PR (ops/sec) Change
create simple object 217,015 228,926 +5.5%
create nested object 112,243 119,777 +6.7%
create 50 objects via Array.from 4,365 4,569 +4.7%
property read 97,509 103,454 +6.1%
Object.keys 69,599 74,539 🟢 +7.1%
Object.entries 45,651 47,866 +4.9%
spread operator 87,159 94,586 🟢 +8.5%
promises.js — 🟢 5 improved, 7 unchanged · avg +6.6%
Benchmark Base (ops/sec) PR (ops/sec) Change
Promise.resolve(value) 290,493 310,032 +6.7%
new Promise(resolve => resolve(value)) 112,184 119,970 +6.9%
Promise.reject(reason) 302,622 324,219 🟢 +7.1%
resolve + then (1 handler) 96,982 106,034 🟢 +9.3%
resolve + then chain (3 deep) 40,497 44,166 🟢 +9.1%
resolve + then chain (10 deep) 13,615 14,246 +4.6%
reject + catch + then 59,877 64,163 🟢 +7.2%
resolve + finally + then 52,925 57,200 🟢 +8.1%
Promise.all (5 resolved) 21,716 22,968 +5.8%
Promise.race (5 resolved) 22,518 23,541 +4.5%
Promise.allSettled (5 mixed) 17,665 18,546 +5.0%
Promise.any (5 mixed) 21,676 22,833 +5.3%
strings.js — 11 unchanged · avg +2.9%
Benchmark Base (ops/sec) PR (ops/sec) Change
string concatenation 248,265 257,838 +3.9%
template literal 243,716 252,342 +3.5%
string repeat 231,301 227,952 -1.4%
split and join 98,947 100,108 +1.2%
indexOf and includes 101,161 102,199 +1.0%
toUpperCase and toLowerCase 148,315 153,690 +3.6%
slice and substring 90,819 95,410 +5.1%
trim operations 109,379 113,706 +4.0%
replace and replaceAll 130,752 133,831 +2.4%
startsWith and endsWith 82,006 84,178 +2.6%
padStart and padEnd 118,672 126,240 +6.4%

Measured on ubuntu-latest x64. Changes within ±7% are considered insignificant.

@frostney frostney merged commit c9bcfe3 into main Feb 20, 2026
4 checks passed
@frostney frostney deleted the feat-print-loc-sloc branch February 20, 2026 23:10
@coderabbitai coderabbitai Bot mentioned this pull request Feb 22, 2026
@frostney frostney added the internal Refactoring, CI, tooling, cleanup label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Refactoring, CI, tooling, cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant