improvement: Add typed equality constructors to avoid reflect.DeepEqual in refreshable debouncing#431
Open
bmoylan wants to merge 2 commits into
Open
improvement: Add typed equality constructors to avoid reflect.DeepEqual in refreshable debouncing#431bmoylan wants to merge 2 commits into
bmoylan wants to merge 2 commits into
Conversation
…al in refreshable debouncing Add a family of constructors that accept or infer an equality function, allowing callers to bypass reflect.DeepEqual when updating refreshable values. This is both more efficient and more correct for types like time.Time where reflect.DeepEqual disagrees with semantic equality. New constructors: NewComparable, NewComparableMap, NewComparableSlice, NewBytes, NewEqualMethod, NewEqualFunc, NewEqualMethodMap, and NewEqualMethodSlice. Each targets a common category of types and wires the appropriate comparison (==, maps.Equal, slices.Equal, bytes.Equal, or a type's own Equal method). Add CacheWith and CacheWithFunc to wrap an existing Refreshable with a typed equality cache, and migrate defaultRefreshable.current from atomic.Value to atomic.Pointer[T] to remove type assertions.
✅ Successfully generated changelog entry!Entry generated via PR titleTo modify this entry, edit PR title using proper format. 📋Changelog Preview💡 Improvements
|
k-simons
requested changes
Mar 23, 2026
|
|
||
| func newZero[T any]() *defaultRefreshable[T] { | ||
| return newDefault(*new(T)) | ||
| return newDefault(*new(T), nil) |
Contributor
There was a problem hiding this comment.
nit, can we never pass in nil and remove all the logic in Update for checking nil? Can't we just pass in reflect.DeepEqual here?
| func newValidRefreshable[M any]() *validRefreshable[M] { | ||
| valid := &validRefreshable[M]{ | ||
| r: newDefault(validRefreshableContainer[M]{}), | ||
| // TODO: Wire equality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a family of constructors that accept or infer an equality function, allowing callers to bypass reflect.DeepEqual when updating refreshable values. This is both more efficient and more correct for types like time.Time where reflect.DeepEqual disagrees with semantic equality, or x509.Certificate which contains function pointer fields that never satisfy reflect.DeepEqual.
New constructors:
NewComparable,NewComparableMap,NewComparableSlice,NewBytes,NewEqualMethod,NewEqualMethodMap, andNewEqualMethodSlice, andNewEqualFunc. Each targets a common category of types and wires the appropriate comparison (==, maps.Equal, slices.Equal, bytes.Equal, or a type's own Equal method).Add
CacheWithandCacheWithFuncto wrap an existing Refreshable with a typed equality cache, and migrate defaultRefreshable.current from atomic.Value to atomic.Pointer[T] to remove type assertions.This change is