Skip to content

Commit

Permalink
optimize Identifier#toHexString() and remove unnecessary calls to imp…
Browse files Browse the repository at this point in the history
…rove performance
  • Loading branch information
davidgyoung committed Oct 27, 2017
1 parent b0afbf1 commit cc797f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3'
}
Expand All @@ -61,7 +61,7 @@ allprojects {

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
buildToolsVersion '26.0.2'

defaultConfig {
// Unfortunately 'com.android.support:appcompat-v7:26.0.0'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
18 changes: 13 additions & 5 deletions src/main/java/org/altbeacon/beacon/Identifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.annotation.TargetApi;
import android.os.Build;

import org.altbeacon.beacon.logging.LogManager;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
Expand Down Expand Up @@ -315,17 +317,23 @@ public boolean equals(Object that) {
return Arrays.equals(mValue, thatIdentifier.mValue);
}

private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

/**
* Represents the value as a hexadecimal String. The String is prefixed with <code>0x</code>. For example 0x0034ab
* @return value as hexadecimal String
*/
public String toHexString() {
StringBuilder sb = new StringBuilder(2 + 2 * mValue.length);
sb.append("0x");
for (byte item : mValue) {
sb.append(String.format("%02x", item));
final int l = mValue.length;
final char[] out = new char[l*2+2];
out[0] = '0';
out[1] = 'x';
for( int i=0,j=2; i<l; i++ ){
out[j++] = HEX_DIGITS[(0xF0 & mValue[i]) >>> 4];
out[j++] = HEX_DIGITS[0x0F & mValue[i]];
}
return sb.toString();
String s = new String(out);
return s;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/altbeacon/beacon/service/RangeState.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ public Callback getCallback() {
public void addBeacon(Beacon beacon) {
if (mRangedBeacons.containsKey(beacon)) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
LogManager.d(TAG, "adding %s to existing range for: %s", beacon, rangedBeacon);
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "adding %s to existing range for: %s", beacon, rangedBeacon);
}
rangedBeacon.updateBeacon(beacon);
}
else {
LogManager.d(TAG, "adding %s to new rangedBeacon", beacon);
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "adding %s to new rangedBeacon", beacon);
}
mRangedBeacons.put(beacon, new RangedBeacon(beacon));
}
}
Expand Down

0 comments on commit cc797f3

Please sign in to comment.