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

Commit

Permalink
Merge pull request #424 from alibaba/feature/performance_massdata
Browse files Browse the repository at this point in the history
LayoutHelper核心链路性能优化
  • Loading branch information
MikeAfc authored Jan 25, 2019
2 parents 8216478 + dd74316 commit 8b94f2c
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 80 deletions.
6 changes: 0 additions & 6 deletions README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,3 @@ recycler.setAdapter(myAdapter);
# 开源许可证

vlayout遵循MIT开源许可证协议。

# 微信群

![](https://img.alicdn.com/tfs/TB11_2_kbSYBuNjSspiXXXNzpXa-167-167.png)

搜索 `tangram_` 或者扫描以上二维码添加 Tangram 为好友,以便我们邀请你入群。
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,3 @@ Before you open an issue or create a pull request, please read [Contributing Gui
# LICENSE

Vlayout is available under the MIT license.

# WeChatGroup

![](https://img.alicdn.com/tfs/TB11_2_kbSYBuNjSspiXXXNzpXa-167-167.png)

Search `tangram_` or scan the QR code above to be invited in WeChat.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.alibaba.android.vlayout.RecyclablePagerAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams;
import com.alibaba.android.vlayout.extend.PerformanceMonitor;
import com.alibaba.android.vlayout.extend.ViewLifeCycleListener;
import com.alibaba.android.vlayout.layout.ColumnLayoutHelper;
import com.alibaba.android.vlayout.layout.FixLayoutHelper;
Expand Down Expand Up @@ -120,7 +121,22 @@ protected void onCreate(Bundle savedInstanceState) {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);

final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
layoutManager.setPerformanceMonitor(new PerformanceMonitor() {

long start;
long end;

@Override
public void recordStart(String phase, View view) {
start = System.currentTimeMillis();
}

@Override
public void recordEnd(String phase, View view) {
end = System.currentTimeMillis();
Log.d("VLayoutActivity", view.getClass().getName() + " " + (end - start));
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
GROUP=com.alibaba.android
ARTIFACT=vlayout
VERSION=1
VERSION_NAME=1.2.13
VERSION_NAME=1.2.17
PACKAGING_TYPE=aar
useNewSupportLibrary=true
systemProp.compileSdkVersion=25
Expand Down
8 changes: 4 additions & 4 deletions vlayout/src/main/java/com/alibaba/android/vlayout/Cantor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public static void reverseCantor(long cantor, long[] result) {
result = new long[2];
}
// reverse Cantor Function
int w = (int) (Math.floor(Math.sqrt(8 * cantor + 1) - 1) / 2);
int t = (w * w + w) / 2;
long w = (long) (Math.floor(Math.sqrt(8 * cantor + 1) - 1) / 2);
long t = (w * w + w) / 2;

int k2 = (int)(cantor - t);
int k1 = w - k2;
long k2 = cantor - t;
long k1 = w - k2;
result[0] = k1;
result[1] = k2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
* An implement of {@link LayoutHelperFinder} which finds layoutHelpers by position
Expand All @@ -46,6 +49,8 @@ public class RangeLayoutHelperFinder extends LayoutHelperFinder {
@NonNull
private List<LayoutHelper> mReverseLayoutHelpers =new LinkedList<>();

private LayoutHelperItem[] mSortedLayoutHelpers = null;

@NonNull
private Comparator<LayoutHelperItem> mLayoutHelperItemComparator = new Comparator<LayoutHelperItem>() {
@Override
Expand All @@ -68,16 +73,21 @@ public void setLayouts(@Nullable List<LayoutHelper> layouts) {
mReverseLayoutHelpers.clear();
mLayoutHelperItems.clear();
if (layouts != null) {
for (int i = 0, size = layouts.size(); i < size; i++) {
LayoutHelper helper = layouts.get(i);
ListIterator<LayoutHelper> iterator = layouts.listIterator();
LayoutHelper helper = null;
while (iterator.hasNext()) {
helper = iterator.next();
mLayoutHelpers.add(helper);
mLayoutHelperItems.add(new LayoutHelperItem(helper));
}
for (int i = layouts.size() - 1; i >= 0; i--) {
mReverseLayoutHelpers.add(layouts.get(i));

while (iterator.hasPrevious()) {
mReverseLayoutHelpers.add(iterator.previous());
}

Collections.sort(mLayoutHelperItems, mLayoutHelperItemComparator);
// Collections.sort(mLayoutHelperItems, mLayoutHelperItemComparator);
mSortedLayoutHelpers = mLayoutHelperItems.toArray(new LayoutHelperItem[mLayoutHelperItems.size()]);
Arrays.sort(mSortedLayoutHelpers, mLayoutHelperItemComparator);
}
}

Expand All @@ -90,18 +100,17 @@ protected List<LayoutHelper> getLayoutHelpers() {
@Nullable
@Override
public LayoutHelper getLayoutHelper(int position) {
final int count = mLayoutHelperItems.size();
if (count == 0) {
if (mSortedLayoutHelpers == null || mSortedLayoutHelpers.length == 0) {
return null;
}
final int count = mSortedLayoutHelpers.length;

int s = 0, e = count - 1, m;
LayoutHelperItem rs = null;

// binary search range
while (s <= e) {
m = (s + e) / 2;
rs = mLayoutHelperItems.get(m);
rs = mSortedLayoutHelpers[m];
if (rs.getStartPosition() > position) {
e = m - 1;
} else if (rs.getEndPosition() < position) {
Expand Down
Loading

0 comments on commit 8b94f2c

Please sign in to comment.