Skip to content

Fix the logic of joining byte arrays when there is no items#925

Merged
0xnm merged 1 commit into
release/1.13.0from
nogorodnikov/fix-array-join-logic
May 5, 2022
Merged

Fix the logic of joining byte arrays when there is no items#925
0xnm merged 1 commit into
release/1.13.0from
nogorodnikov/fix-array-join-logic

Conversation

@0xnm

@0xnm 0xnm commented May 4, 2022

Copy link
Copy Markdown
Member

What does this PR do?

Fixes a silly bug: size taken by separators could be negative in case of empty collection (doesn't impact any data upload though).

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm requested a review from a team as a code owner May 4, 2022 15:44
@codecov-commenter

codecov-commenter commented May 4, 2022

Copy link
Copy Markdown

Codecov Report

Merging #925 (4f2f927) into release/1.13.0 (bbdff1e) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@                Coverage Diff                 @@
##           release/1.13.0     #925      +/-   ##
==================================================
- Coverage           83.05%   83.04%   -0.02%     
==================================================
  Files                 267      267              
  Lines                9057     9060       +3     
  Branches             1456     1457       +1     
==================================================
+ Hits                 7522     7523       +1     
- Misses               1138     1141       +3     
+ Partials              397      396       -1     
Impacted Files Coverage Δ
...atadog/android/core/internal/utils/ByteArrayExt.kt 83.33% <100.00%> (+0.41%) ⬆️
...android/log/internal/logger/TelemetryLogHandler.kt 75.00% <0.00%> (-25.00%) ⬇️
...ndroid/core/internal/persistence/file/EventMeta.kt 80.00% <0.00%> (-10.00%) ⬇️
...rc/main/java/com/datadog/opentracing/DDTracer.java 55.65% <0.00%> (-0.42%) ⬇️
.../src/main/kotlin/com/datadog/android/log/Logger.kt 95.83% <0.00%> (-0.03%) ⬇️
.../kotlin/com/datadog/android/ktx/rum/ClosableExt.kt 100.00% <0.00%> (ø)
...om/datadog/android/rum/webview/RumWebViewClient.kt 100.00% <0.00%> (ø)
.../android/webview/internal/rum/WebViewRumFeature.kt 100.00% <0.00%> (ø)
...tadog/android/fresco/DatadogFrescoCacheListener.kt 100.00% <0.00%> (ø)
...ndroid/telemetry/internal/TelemetryEventHandler.kt 92.06% <0.00%> (+0.26%) ⬆️
... and 2 more

Comment on lines +44 to +46
this.sumOf { it.size } +
prefix.size + suffix.size + separator.size * (this.size - 1)
prefix.size + suffix.size +
if (this.isNotEmpty()) separator.size * (this.size - 1) else 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This begins to be hard to read, it'd be nice to split that into variables, e.g.:

val dataSize = this.sumOf { it.size }
val separatorsSize = if (this.isNotEmpty()) separator.size * (this.size - 1) else 0
val size = dataSize + separatorsSize + prefix.size + suffix.size
val result = ByteArray(size)

@0xnm
0xnm force-pushed the nogorodnikov/fix-array-join-logic branch from 4f2f927 to c35c5a1 Compare May 5, 2022 07:30
@0xnm
0xnm requested a review from xgouchet May 5, 2022 07:31
@0xnm
0xnm merged commit 18b8937 into release/1.13.0 May 5, 2022
@0xnm
0xnm deleted the nogorodnikov/fix-array-join-logic branch May 5, 2022 14:54
@xgouchet xgouchet added this to the 1.13.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants