Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Initialize XCallback.extra only if needed
Browse files Browse the repository at this point in the history
This is a little API change, but it doesn't seemed to be used often
anyway. However, it improves the speed of hooks and allocates less
unneeded objects that need to be GC'd later.
  • Loading branch information
rovo89 committed Nov 8, 2013
1 parent d4f7fe2 commit 3c18f6f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/de/robv/android/xposed/callbacks/XCallback.java
Expand Up @@ -18,13 +18,7 @@ public XCallback(int priority) {

public static class Param {
public final TreeSet<? extends XCallback> callbacks;
/**
* This can be used to store anything for the scope of the callback.
* Use this instead of instance variables.
* @see #getObjectExtra
* @see #setObjectExtra
*/
public final Bundle extra = new Bundle();
private Bundle extra;

protected Param() {
callbacks = null;
Expand All @@ -37,17 +31,29 @@ protected Param(TreeSet<? extends XCallback> callbacks) {
}
}

/**
* This can be used to store anything for the scope of the callback.
* Use this instead of instance variables.
* @see #getObjectExtra
* @see #setObjectExtra
*/
public synchronized Bundle getExtra() {
if (extra == null)
extra = new Bundle();
return extra;
}

/** @see #setObjectExtra */
public Object getObjectExtra(String key) {
Serializable o = extra.getSerializable(key);
Serializable o = getExtra().getSerializable(key);
if (o instanceof SerializeWrapper)
return ((SerializeWrapper) o).object;
return null;
}

/** Provides a wrapper to store <code>Object</code>s in <code>extra</code>. */
public void setObjectExtra(String key, Object o) {
extra.putSerializable(key, new SerializeWrapper(o));
getExtra().putSerializable(key, new SerializeWrapper(o));
}

private static class SerializeWrapper implements Serializable {
Expand Down

0 comments on commit 3c18f6f

Please sign in to comment.