Skip to content

Commit

Permalink
Merge pull request #615 from AltBeacon/optimize-identifer-hex-conversion
Browse files Browse the repository at this point in the history
Fix performance problems caused by Identifier#toHexString
  • Loading branch information
davidgyoung authored Nov 6, 2017
2 parents 6c3c9e0 + caa5d24 commit 8cd351f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Development

Bug Fixes:
- Fix performance problems when using identifiers 3-15 bytes caused by
Identifier#toHexString(). (#615, David G. Young)

### 2.12.3 / 2017-10-14

[Full Changelog](https://github.com/AltBeacon/android-beacon-library/compare/2.12.2...2.12.3)
Expand Down
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
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ machine:
version: openjdk8
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "tools,android-26,build-tools-26.0.0,platform-tools,extra-android-m2repository,extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "tools,android-26,build-tools-26.0.2,platform-tools,extra-android-m2repository,extra-google-m2repository"

general:
branches:
ignore:
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 8cd351f

Please sign in to comment.