Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 078bdb4c authored by William Escande's avatar William Escande
Browse files

AndroidFrameworkEfficientStrings: formatSimple x

Logging some bytes in hexa require to add some utility capabilities

solving
[AndroidFrameworkEfficientStrings] Simple format strings can be replaced
with TextUtils.formatSimple() for a 6x performance improvement

Bug: 344658662
Test: None
Flag: Exempt refactor
Change-Id: Icaa256a7ec2bfbd251ea16301894e435d8b1c24d
parent faea5cda
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ public final class Utils {
            if (idx != 0) {
                sb.append(" ");
            }
            sb.append(String.format("%02x", valueBuf[idx]));
            sb.append(formatSimple("%02x", valueBuf[idx]));
        }
        return sb.toString();
    }
@@ -1317,7 +1317,7 @@ public final class Utils {
     *   <li>{@code %d} for {@code int} or {@code long}
     *   <li>{@code %f} for {@code float} or {@code double}
     *   <li>{@code %s} for {@code String}
     *   <li>{@code %x} for hex representation of {@code int} or {@code long}
     *   <li>{@code %x} for hex representation of {@code int} or {@code long} or {@code byte}
     *   <li>{@code %%} for literal {@code %}
     *   <li>{@code %04d} style grammar to specify the argument width, such as {@code %04d} to
     *       prefix an {@code int} with zeros or {@code %10b} to prefix a {@code boolean} with
@@ -1382,6 +1382,8 @@ public final class Utils {
                            repl = Integer.toHexString((int) arg);
                        } else if (arg instanceof Long) {
                            repl = Long.toHexString((long) arg);
                        } else if (arg instanceof Byte) {
                            repl = Integer.toHexString(Byte.toUnsignedInt((byte) arg));
                        } else {
                            throw new IllegalArgumentException(
                                    "Unsupported hex type " + arg.getClass());
+1 −1
Original line number Diff line number Diff line
@@ -508,7 +508,7 @@ public class MetricsLogger {
        StringBuilder hexString = new StringBuilder();
        byte[] hashBytes = getSha256(name);
        for (byte b : hashBytes) {
            hexString.append(String.format("%02x", b));
            hexString.append(Utils.formatSimple("%02x", b));
        }
        return hexString.toString();
    }
+2 −2
Original line number Diff line number Diff line
@@ -607,10 +607,10 @@ public class BluetoothMapUtils {
                        b2 = (byte) (b2 - 'a' + 10);
                    }

                    Log.v(TAG, "Resulting nibble values: " + String.format("b1=%x b2=%x", b1, b2));
                    Log.v(TAG, "Resulting nibble values: " + formatSimple("b1=%x b2=%x", b1, b2));

                    output[out++] = (byte) (b1 << 4 | b2); // valid hex char, append
                    Log.v(TAG, "Resulting value: " + String.format("0x%2x", output[out - 1]));
                    Log.v(TAG, "Resulting value: " + formatSimple("0x%2x", output[out - 1]));
                    continue;
                }
                Log.w(
+2 −0
Original line number Diff line number Diff line
@@ -336,6 +336,8 @@ public class UtilsTest {

        expect.that(formatSimple("%x", 42)).isEqualTo("2a");
        expect.that(formatSimple("%x", 281474976710656L)).isEqualTo("1000000000000");
        byte myByte = 0x42;
        expect.that(formatSimple("%x", myByte)).isEqualTo("42");

        expect.that(formatSimple("%%")).isEqualTo("%");
    }