Commit 4936611
Fold OptimizedTagMap into a final class TagMap (#11967)
Fold OptimizedTagMap into a final class TagMap (drop the interface)
TagMap was an interface with a single implementation, OptimizedTagMap. The
split was vestigial scaffolding from when a second (HashMap-backed) impl
existed; with one impl it is false generalization. Collapse them into one
`public final class TagMap`:
- The interface's abstract method declarations are removed; OptimizedTagMap's
bodies become TagMap's methods.
- Nested types that were implicitly `public static` in the interface
(EntryChange, EntryRemoval, EntryReader, Entry, Ledger) are now written out
explicitly as `public static`.
- Static factories (create/fromMap/ledger/...) and the EMPTY constant become
explicit `public static` members; the EmptyHolder lazy-init note is updated
now that there is no interface<->impl class-init cycle.
- putAll(TagMap) loses its `instanceof` dispatch (always true once there is one
class) and calls the fast path directly.
No behavior change; motivation is code simplicity, not performance (a single
final class is monomorphic by construction, but CHA already devirtualized the
sole impl). Public API is preserved, so callers are unchanged; the 3 tests that
referenced OptimizedTagMap now reference TagMap.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop EmptyHolder, make factories final, simplify test-helper instanceof
Post-fold tidy, all TagMap-scoped:
- Remove EmptyHolder: with one class there is no interface<->impl class-init
cycle to break, and the private constructor reads no statics, so EMPTY is a
direct `new TagMap(new Object[1], 0)` initializer.
- Static factories (create/fromMap/ledger/...) are now `public static final`
(not expressible on the old interface).
- assertSize/assertNotEmpty/assertEmpty/checkIntegrity test helpers dropped
their now-always-true `instanceof TagMap` guard + redundant cast.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Restore null-contract annotations lost when folding away the interface
The interface -> final-class fold removed the TagMap interface decls, which
carried the @Nullable/@nonnull param annotations from #11963. Re-home them
onto the now-concrete methods: @nonnull tag keys and strict-setter values,
@nullable on the set(EntryReader)/getAndSet(Entry) sinks (+ the getAndSet
contract javadoc). The null-tolerance behavior was already preserved by the
fold; this restores the self-describing contract on the write surface.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mark fromMap/fromMapImmutable map param @nonnull
Per review: these factories NPE on a null map (map.size()/putAll), so the
input is non-null by contract.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent 554134a commit 4936611
4 files changed
Lines changed: 160 additions & 406 deletions
File tree
- internal-api/src
- main/java/datadog/trace/api
- test/java/datadog/trace/api
0 commit comments