Skip to content

Make one more function inine and use a table instead of switch/case#60

Merged
masatake merged 2 commits intouniversal-ctags:masterfrom
masatake:more-inline
Oct 19, 2025
Merged

Make one more function inine and use a table instead of switch/case#60
masatake merged 2 commits intouniversal-ctags:masterfrom
masatake:more-inline

Conversation

@masatake
Copy link
Member

No description provided.

@masatake masatake requested a review from Copilot October 18, 2025 22:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors escape sequence handling to improve performance by replacing switch/case statements with a lookup table and marking hot path functions as inline.

  • Replaces switch/case with a altchars lookup table for escape sequence handling
  • Adds READTAGS_INLINE to two hot path functions: readTagCharacter and unescapeInPlace
  • Updates performance benchmarks showing ~40% improvement in execution time

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
readtags.c Introduces lookup table for escape sequences, adds inline keywords to hot path functions
NEWS.md Documents performance improvements with updated benchmark results

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

case 'x':
if (isxdigit (p[1]) && isxdigit (p[2]))
default:
a = altchars[*p];
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

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

Potential out-of-bounds array access. The pointer *p is a signed char that's cast to unsigned char for array indexing, but there's no validation that *p is within the valid array bounds before accessing altchars[*p]. If *p contains a value >= 255, this will access memory beyond the array (especially problematic given the array size issue in Comment 1).

Suggested change
a = altchars[*p];
a = (*p < 0xff) ? altchars[*p] : 0;

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +185 to +194
unsigned char a;
switch (*p)
{
case 't': c = '\t'; p++; break;
case 'r': c = '\r'; p++; break;
case 'n': c = '\n'; p++; break;
case '\\': c = '\\'; p++; break;
/* Universal-CTags extensions */
case 'a': c = '\a'; p++; break;
case 'b': c = '\b'; p++; break;
case 'v': c = '\v'; p++; break;
case 'f': c = '\f'; p++; break;
case 'x':
if (isxdigit (p[1]) && isxdigit (p[2]))
default:
a = altchars[*p];
if (a) {
c = a;
p++;
}
break;
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

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

The switch statement structure is incorrect. The default case is now positioned before the case 'x': statement (line 195), which means the hexadecimal escape sequence handling will never be reached. The default case should be moved after all other case statements.

Copilot uses AI. Check for mistakes.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@codecov
Copy link

codecov bot commented Oct 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.15%. Comparing base (2275e9d) to head (7661a7f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   77.94%   78.15%   +0.20%     
==========================================
  Files          16       16              
  Lines        1705     1703       -2     
  Branches      153      154       +1     
==========================================
+ Hits         1329     1331       +2     
+ Misses        376      372       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@masatake
Copy link
Member Author

The coverage is much lower than I expected.

@masatake masatake merged commit ea0aa55 into universal-ctags:master Oct 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants