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

Small nit #15

Open
maplant opened this issue Jul 11, 2016 · 2 comments
Open

Small nit #15

maplant opened this issue Jul 11, 2016 · 2 comments

Comments

@maplant
Copy link

maplant commented Jul 11, 2016

Hey there, I don't really want to make a pull request here so I thought I'd just make an issue. Sorry if that's not proper etiquette! By the way, love the work.
The following lines of code appear in the source code:

erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
if (row) {
        for (j = E.coloff; j < (E.cx+E.coloff); j++) {
            if (j < row->size && row->chars[j] == TAB) cx += 7-((cx)%8);
            cx++;
        }
}

Surely this should be simplified slightly to:

if (filerow < E.numrows) {
        erow *row = &E.row[filerow];
        for (j = E.coloff; j < (E.cx+E.coloff); j++) {
            if (j < row->size && row->chars[j] == TAB) cx += 7-((cx)%8);
            cx++;
        }
 }

It seems a little off to make the conditional based off of the result of another conditional that appears literally one line above.

@practicalswift
Copy link

@DataAnalysisCosby Your simplification looks better in this case. I'm guessing the reasoning behind this structure it is probably to keep it consistent with the other usages of erow *row = …; in the code base:

$ grep 'erow \*row = (' *.c
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
    erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];

@SevenBits
Copy link

@DataAnalysisCosby @practicalswift I would also agree that this simplification is an improvement. It also makes the purpose of the code much more clear.

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

No branches or pull requests

3 participants