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

Add good_words to project dict more efficiently #1261

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/lib/Guiguts/SpellCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,16 @@ sub spelladdword {
}

#
# Add a word to the project dictionary
# Optional second argument if it's a bad word
# Add a single word to the project dictionary and save it - slow if used for bulk additions
Copy link
Member

Choose a reason for hiding this comment

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

This branch is undoubtedly faster than master, but this comment seems to imply that it's still saving after each addition? Or am I misinterpreting something?

Copy link
Collaborator Author

@windymilla windymilla Oct 14, 2023

Choose a reason for hiding this comment

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

That function spelladdword is still used for adding a single word to the project dictionary - I added the word "single" to the comment, and that it saves the dictionary, to emphasise that. However, it used to be called multiple times when a good word list was added - I now add all the words to the internal structures, then save the dictionary once for that case, so don't use this function at all for that. The comment that it is "slow if used for bulk additions" is intended to alert a future developer not to use it for adding lots of words.

sub spellmyaddword {
my $textwindow = $::textwindow;
my $term = shift;
my $bad = shift;
unless ($term) {
::soundbell();
return;
}
return if $term =~ /^\s*$/;
( $bad ? $::projectbadwords{$term} : $::projectdict{$term} ) = '';
$::projectdict{$term} = '';
spellsaveprojdict();
}

Expand Down Expand Up @@ -502,7 +500,7 @@ sub spelladdgoodwords {
while ( my $line = <$fh> ) {
$line =~ s/\s+$//;
next if $line eq '';
spellmyaddword($line);
$::projectdict{$line} = '';
}
close($fh);

Expand All @@ -511,10 +509,11 @@ sub spelladdgoodwords {
while ( my $line = <$fh> ) {
$line =~ s/\s+$//;
next if $line eq '';
spellmyaddword( $line, "bad" );
$::projectbadwords{$line} = '';
}
close($fh);
}
spellsaveprojdict();
::unbusy();
} else {
::warnerror("Could not open good_words.txt");
Expand Down