Skip to content

Commit

Permalink
feat(android): optimize addUpdateNodeIfNeeded time cost
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel authored and hippy-actions[bot] committed Sep 7, 2023
1 parent eec0d79 commit b0a48ce
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;

import android.text.TextUtils;
Expand All @@ -58,11 +59,12 @@
public class RenderManager {

private static final String TAG = "RenderManager";
private static final int INITIAL_UPDATE_NODE_SIZE = 1 << 9;
private boolean isBatching = false;
@NonNull
private final ControllerManager mControllerManager;
@NonNull
private final Map<Integer, List<RenderNode>> mUIUpdateNodes = new HashMap<>();
private final Map<Integer, LinkedHashSet<RenderNode>> mUIUpdateNodes = new HashMap<>();

public RenderManager(Renderer renderer) {
mControllerManager = new ControllerManager(renderer);
Expand Down Expand Up @@ -166,12 +168,12 @@ public void createNode(int rootId, int id, int pid, int index,
}

public void addUpdateNodeIfNeeded(int rootId, RenderNode node) {
List<RenderNode> updateNodes = mUIUpdateNodes.get(rootId);
LinkedHashSet<RenderNode> updateNodes = mUIUpdateNodes.get(rootId);
if (updateNodes == null) {
updateNodes = new ArrayList<>();
updateNodes = new LinkedHashSet<>(INITIAL_UPDATE_NODE_SIZE);
updateNodes.add(node);
mUIUpdateNodes.put(rootId, updateNodes);
} else if (!updateNodes.contains(node)) {
} else {
updateNodes.add(node);
}
}
Expand Down Expand Up @@ -344,7 +346,7 @@ public boolean isBatching() {
}

public void batch(int rootId) {
List<RenderNode> updateNodes = mUIUpdateNodes.get(rootId);
LinkedHashSet<RenderNode> updateNodes = mUIUpdateNodes.get(rootId);
if (updateNodes == null) {
return;
}
Expand Down

0 comments on commit b0a48ce

Please sign in to comment.