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

no unnecessary string modifications #543

Merged

Conversation

benoit-pierre
Copy link
Contributor

@benoit-pierre benoit-pierre commented Oct 24, 2023

The extra value_type & operator [] accessors would get picked-up over the normal readonly one: value_type operator [], resulting in unnecessary calls to modify() (triggering an allocation+copy if the reference count is not 1). Get rid of the former, and fix lastChar and firstChar method to also be read-only. Additionally, avoid using the at() method (prefer an explicit modify()[…] when needed), and remove it.

Note: depends on koreader/koreader-base#1675.


This change is Reviewable

@benoit-pierre benoit-pierre marked this pull request as draft October 24, 2023 21:48
@Frenzie Frenzie requested a review from poire-z October 25, 2023 08:29
@poire-z
Copy link
Contributor

poire-z commented Oct 26, 2023

depends on koreader/koreader-base#1675

Because crskin.cpp & wolutil.cpp did use some of the stuff you removed?

@@ -617,12 +617,13 @@ lString32 MathMLHelper::getMathMLAdjustedText(ldomNode * node, const lChar32 * t
// (no substitution for "normal")
if ( mathvariant != mathml_mathvariant_normal ) {
len = mtext.length();
lChar32 *ptr = mtext.modify();
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a bit less object oriented, if we need to get to the raw char array to modify the string.
Any idea for a new lStringXY method(s) to keep it opaque ? (ie mtext.replaceCharAt(i, c))

Was I really the only user of this feature, in mathml.cpp ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer an explicit access myself. Plus it means you don't have to go through a call to modify() for each character.

@benoit-pierre
Copy link
Contributor Author

depends on koreader/koreader-base#1675

Because crskin.cpp & wolutil.cpp did use some of the stuff you removed?

There's one use in there, yes.

Copy link
Contributor

@poire-z poire-z left a comment

Choose a reason for hiding this comment

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

Fine.
I would squash these 4 commits as a single one, as they end up being dependant:

Avoid unnecessary string modifications 

See https://github.com/koreader/crengine/pull/543:
(+ the text of the 4 commits we'll get with Squash)

But waiting for you to unmark Draft if you think this is ready.

@benoit-pierre
Copy link
Contributor Author

Fine. I would squash these 4 commits as a single one, as they end up being dependant:

Why? There's nothing to be gained, you loose context in the subject line (e.g. in blame), end-up with not strictly related changes in the commit. Generally speaking: more (simpler) commits = better, no?

@poire-z
Copy link
Contributor

poire-z commented Oct 26, 2023

Generally speaking: more (simpler) commits = better, no?

For the review, yes indeed! Thank you for that.
But later, when using git log or git blame or git show, having to follow the related (because each is nearly possible because of the previous one - they may compile, but they may not make sense :)) changes across 4 (super small) commits feels less easy - and they are small and localized enough that it should be followable in a single relatively small final commit.

If you really want to keep the individual commits, please add a common prefix Avoid unnecessary string modifications [1/4]:... in the commit subject, so we know in git log and blame they are not really standalone.

benoit-pierre added a commit to benoit-pierre/crengine that referenced this pull request Oct 26, 2023
See koreader#543:

- lvstring: drop `& operator []` accessors, as they end up
  always being used, even for read-only lookup, triggering
  unnecessary calls to `modify()` strings.

- avoid unnecessary use of `lStringXX:at(…)` (which could
  trigger a call to `modify()`).

- lvstring: fix `lastChar/firstChar` implementations: don't
  use `at()`, which could trigger a call to `modify()`.

- lvstring: drop `at()` methods: not used anymore.
@benoit-pierre benoit-pierre force-pushed the pr/no_unnecessary_string_modifications branch from b2e3ddc to 60506b8 Compare October 26, 2023 21:37
@benoit-pierre
Copy link
Contributor Author

I disagree, but OK, your project, your rules.

@poire-z
Copy link
Contributor

poire-z commented Oct 26, 2023

No... you shouldn't have done this yourself. We should have kept your 4 commits in this PR, for reference. (See @NiLuJe 's PRs :) Now, we can't see them anywhere, and the above discussion has lost infos and context :(
Only in the squashed commit in master we would have them merged as a single commit - which is fine in the whole crengine context.
We can always go back to the PR when needed to see more context and the individual work units, when it happens to be needed.

@benoit-pierre benoit-pierre force-pushed the pr/no_unnecessary_string_modifications branch from 60506b8 to 082a9f0 Compare October 26, 2023 21:47
@benoit-pierre
Copy link
Contributor Author

It's already annoying to not be able to use git branch --merged to cleanup merged work, but it's even worse if I split commits and they end-up being squashed. Next time I won't split them, it's more work for me.

@poire-z
Copy link
Contributor

poire-z commented Oct 26, 2023

I understand.
The individual small commits help with reviewing, but for #538 and this PR, I would have been ok reviewing and understanding it as a single commit.
It all depends on the amount of changes and how they are localized/related.
#536 needed the individual commits for review, and they deserve to be kept as-is in master - I think.

(You still need to remove the Draft state when you want to proceed.)

@benoit-pierre
Copy link
Contributor Author

benoit-pierre commented Oct 26, 2023

(You still need to remove the Draft state when you want to proceed.)

I'll remove it once koreader/koreader-base#1675 and its dependent are merged.

@poire-z
Copy link
Contributor

poire-z commented Oct 26, 2023

I'll remove it once koreader/koreader-base#1675 and its dependent are merged.

Also Draft.
Or you mean koreader/koreader-base#1679 should go first?

@benoit-pierre
Copy link
Contributor Author

I'll remove it once koreader/koreader-base#1675 and its dependent are merged.

Also Draft. Or you mean koreader/koreader-base#1679 should go first?

That one can wait (this way I'll cleanup the no longer necessary crskin related defines).

As they end up always being used, even for read-only lookup,
triggering unnecessary calls to `modify()` strings.
Which could trigger a `modify()`.
Don't use `at()`, which could trigger a call to `modify()`.
Not used anymore.
@benoit-pierre benoit-pierre force-pushed the pr/no_unnecessary_string_modifications branch from 082a9f0 to 0b0c536 Compare November 1, 2023 13:32
@benoit-pierre benoit-pierre marked this pull request as ready for review November 1, 2023 13:33
@poire-z poire-z merged commit 22191fd into koreader:master Nov 1, 2023
1 check passed
@benoit-pierre benoit-pierre deleted the pr/no_unnecessary_string_modifications branch November 1, 2023 14:12
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