Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwoWayListVM里面这样的addAll不会很费时间和内存吗? #17

Closed
vejei opened this issue Feb 18, 2019 · 1 comment
Closed

TwoWayListVM里面这样的addAll不会很费时间和内存吗? #17

vejei opened this issue Feb 18, 2019 · 1 comment

Comments

@vejei
Copy link

vejei commented Feb 18, 2019

open val loadTaskObserver : ((List<T>, Refreshable?) -> Observer<List<T>>)? = { originData: List<T>, refreshable: Refreshable? ->
        object: Observer<List<T>>{
            override fun onNext(netData: List<T>) {
                val lastItem = if(!originData.isEmpty()) originData[originData.size-1] else null
                val isLoadMore = lastItem != null

                val newData = ArrayList<T>()
                if (isLoadMore) {
                    newData.addAll(originData)
                }
                newData.addAll(netData)

                data.clear()
                data.addAll(newData)
            }

            override fun onComplete() {
                refreshable?.endRefresh()
            }

            override fun onError(e: Throwable) {}

            override fun onSubscribe(d: Disposable) {}
        }
    }

TwoWayListVM里面加载数据是每次都把原数据复制一次,随着数据的加载,originData肯定是越来越大的,每次都把它复制一遍不会很费时间和内存吗?尤其是它变得越来越大的时候,虽然整个过程是用RxJava做了异步的

@fashare2015
Copy link
Owner

@Zeleven 其实还好,addAll() 是浅拷贝不是深拷贝(clone)

@vejei vejei closed this as completed Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants