Skip to content

Commit 3273d67

Browse files
sfreilichcopybara-github
authored andcommitted
Return early in InProgresStroke.UpdateShape when no update needed
PiperOrigin-RevId: 874385172
1 parent 87fe423 commit 3273d67

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

ink/strokes/in_progress_stroke.cc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ absl::Status InProgressStroke::EnqueueInputs(
115115
return absl::OkStatus();
116116
}
117117

118+
bool InProgressStroke::HasQueuedInputs() const {
119+
return !queued_real_inputs_.IsEmpty() ||
120+
!queued_predicted_inputs_.IsEmpty() ||
121+
// The only thing queued was empty, but a previous prediction was
122+
// cleared as a result.
123+
(queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0);
124+
}
125+
118126
absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) {
119127
if (!brush_.has_value()) {
120128
return absl::FailedPreconditionError(
@@ -126,11 +134,14 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) {
126134
!status.ok()) {
127135
return status;
128136
}
129-
if (inputs_are_finished_ || !queued_real_inputs_.IsEmpty() ||
130-
!queued_predicted_inputs_.IsEmpty() ||
131-
(queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0)) {
137+
current_elapsed_time_ = current_elapsed_time;
138+
139+
if (HasQueuedInputs()) {
132140
// Erase any old predicted inputs.
133141
processed_inputs_.Erase(real_input_count_);
142+
} else if (!ChangesWithTime()) {
143+
// Exit early if no change is needed.
144+
return absl::OkStatus();
134145
}
135146

136147
if (absl::Status status = processed_inputs_.Append(queued_real_inputs_);
@@ -152,8 +163,6 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) {
152163
return status;
153164
}
154165

155-
current_elapsed_time_ = current_elapsed_time;
156-
157166
input_modeler_.ExtendStroke(queued_real_inputs_, queued_predicted_inputs_,
158167
current_elapsed_time);
159168
uint32_t num_coats = BrushCoatCount();
@@ -172,12 +181,7 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) {
172181
}
173182

174183
bool InProgressStroke::NeedsUpdate() const {
175-
if (!queued_real_inputs_.IsEmpty() || !queued_predicted_inputs_.IsEmpty() ||
176-
// There are processed predicted inputs to be cleared.
177-
(queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0)) {
178-
return true;
179-
}
180-
return ChangesWithTime();
184+
return HasQueuedInputs() || ChangesWithTime();
181185
}
182186

183187
bool InProgressStroke::ChangesWithTime() const {

ink/strokes/in_progress_stroke.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ class InProgressStroke {
271271

272272
absl::Status ValidateNewElapsedTime(Duration32 current_elapsed_time) const;
273273

274+
// Whether `UpdateShape` might be needed due to a prior call to
275+
// `EnqueueInputs`.
276+
bool HasQueuedInputs() const;
277+
274278
std::optional<Brush> brush_;
275279
// Real and predicted inputs that have been queued by calls to
276280
// `EnqueueInputs()` since the last call to `UpdateShape()`.

0 commit comments

Comments
 (0)