Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Optimize diff algorithm #106

Merged
merged 5 commits into from
Apr 25, 2022
Merged

Optimize diff algorithm #106

merged 5 commits into from
Apr 25, 2022

Conversation

Goooler
Copy link
Owner

@Goooler Goooler commented Apr 25, 2022

Follow up #103.

        /**
         * Called to check whether two objects represent the same item.
         * <p>
         * For example, if your items have unique ids, this method should check their id equality.
         * <p>
         * Note: {@code null} items in the list are assumed to be the same as another {@code null}
         * item and are assumed to not be the same as a non-{@code null} item. This callback will
         * not be invoked for either of those cases.
         *
         * @param oldItem The item in the old list.
         * @param newItem The item in the new list.
         * @return True if the two items represent the same object or false if they are different.
         * @see Callback#areItemsTheSame(int, int)
         */
        public abstract boolean areItemsTheSame(@NonNull T oldItem, @NonNull T newItem);
        /**
         * Called to check whether two items have the same data.
         * <p>
         * This information is used to detect if the contents of an item have changed.
         * <p>
         * This method to check equality instead of {@link Object#equals(Object)} so that you can
         * change its behavior depending on your UI.
         * <p>
         * For example, if you are using DiffUtil with a
         * {@link RecyclerView.Adapter RecyclerView.Adapter}, you should
         * return whether the items' visual representations are the same.
         * <p>
         * This method is called only if {@link #areItemsTheSame(T, T)} returns {@code true} for
         * these items.
         * <p>
         * Note: Two {@code null} items are assumed to represent the same contents. This callback
         * will not be invoked for this case.
         *
         * @param oldItem The item in the old list.
         * @param newItem The item in the new list.
         * @return True if the contents of the items are the same or false if they are different.
         * @see Callback#areContentsTheSame(int, int)
         */
        public abstract boolean areContentsTheSame(@NonNull T oldItem, @NonNull T newItem);

@Goooler Goooler added the enhancement New feature or request label Apr 25, 2022
@Goooler Goooler added this to the 1.6.0 milestone Apr 25, 2022
Comment on lines +20 to +21
override fun isItemTheSame(that: IDiffVhModelType): Boolean =
(that as? Repo)?.fullName == this.fullName
Copy link
Owner Author

Choose a reason for hiding this comment

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

@Goooler Goooler merged commit 5c28b52 into trunk Apr 25, 2022
@Goooler Goooler deleted the diff_optimize branch April 25, 2022 06:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant