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

Refactor to remove STRLEN() part 5 #14648

Closed
wants to merge 12 commits into from
Closed

Conversation

basilisk0315
Copy link
Contributor

Refactor regexp.c, regexp_bt.c and regexp_nfa.c to remove STRLEN() calls.

At the same time improve the efficiency of character class lookups in function get_char_class().

My measurements on an empty buffer show no difference in the number of comparisons (~100). This is because my start up files use '[[:alnum:]]' almost exclusively. However, each comparison originally included a call to STRLEN() and STRNCMP(). After the change each comparison only uses STRNCMP().

Cheers
John

@benknoble
Copy link
Contributor

I suspect you really want to rebase this branch on to the latest master rather than merging in master on top of other commits which have presumably already been merged here?


The diff indicates this patch series also adds some uses of STRLEN, is that right?

@basilisk0315
Copy link
Contributor Author

Yes I think you're right. I probably should rebase.

Yes some calls to STRLEN() have been added.

@chrisbra
Copy link
Member

Yes, if possible, please try to rebase and get rid of all previously merged changes. That helps.

@basilisk0315
Copy link
Contributor Author

Sorry to be a pain, but can someone please give me instructions on the best way to rebase? I have been looking around online and just got myself confused. Thanks.

@benknoble
Copy link
Contributor

benknoble commented Apr 30, 2024

Sorry to be a pain, but can someone please give me instructions on the best way to rebase? I have been looking around online and just got myself confused. Thanks.

@basilisk0315 what you want to do is something like (assuming you are on the branch of interest):

git pull --rebase https://github.com/vim/vim master

If you have a remote upstream that points at this repo already, you can do

git fetch --all
git rebase upstream/master

You'll have to push --force-with-lease when finished.

@benknoble
Copy link
Contributor

benknoble commented Apr 30, 2024

Nice! I think @chrisbra has to pull branches to merge them anyway because of the patch numbers (#14518) and commit messages, so he and other maintainers can rebase/squash as needed then, but it helps review to see a focused topic branch.

@basilisk0315
Copy link
Contributor Author

Thanks for the info @benknoble. I hope I have done it correctly.

src/regexp.c Outdated
* Get length of line "lnum", which is relative to "reg_firstlnum".
*/
static colnr_T
reg_getlinelen(linenr_T lnum)
Copy link
Member

Choose a reason for hiding this comment

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

we use _len suffix typically, so I think this deserves to be reg_getline_len() as well

char_u *p;
char_u *newsub = source;
Copy link
Member

Choose a reason for hiding this comment

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

don't move this line

src/regexp.c Outdated
char_u *p;
char_u *newsub = source;
size_t newsublen;
Copy link
Member

Choose a reason for hiding this comment

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

I think we can go with size_t newsublen = 0;

src/regexp.c Outdated
size_t postfixlen;
size_t tmpsublen;

if (!have_newsublen)
Copy link
Member

Choose a reason for hiding this comment

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

and here: if (newsublen == 0) then we don't need the have_newsublen var

rex.reg_firstlnum = save_first;
rex.reg_maxline = save_max;
return len;
}
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates code with the function above reg_getline_submatch(). Can we refactor both into a a common function?

@chrisbra
Copy link
Member

chrisbra commented May 6, 2024

thanks, I had to wrap my head around several times for some of the pointer arithmethics :/ but I think I got it now. If you could please refactor reg_getline_submatch() and reg_getline_submatch_len() into a common function please?

@basilisk0315
Copy link
Contributor Author

Hi Christian, no worries. Stay tuned...

@chrisbra
Copy link
Member

thanks!

@chrisbra chrisbra closed this in 82792db May 11, 2024
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.

None yet

3 participants