From 902506b2b8d28cbdcd949d9dbf3b98dd31d62af8 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 10 Aug 2016 13:50:25 +0200 Subject: [PATCH] move legacy utility method into migration class --- .../main/java/com/fsck/k9/helper/Utility.java | 34 ------------------- .../mailstore/migrations/MigrationTo56.java | 32 ++++++++++++++++- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/helper/Utility.java b/k9mail/src/main/java/com/fsck/k9/helper/Utility.java index 69d906f11..f0b4e9f59 100644 --- a/k9mail/src/main/java/com/fsck/k9/helper/Utility.java +++ b/k9mail/src/main/java/com/fsck/k9/helper/Utility.java @@ -128,40 +128,6 @@ public class Utility { return false; } - /** - * A fast version of URLDecoder.decode() that works only with UTF-8 and does only two - * allocations. This version is around 3x as fast as the standard one and I'm using it - * hundreds of times in places that slow down the UI, so it helps. - */ - public static String fastUrlDecode(String s) { - - byte[] bytes = s.getBytes(Charset.forName("UTF-8")); - byte ch; - int length = 0; - for (int i = 0, count = bytes.length; i < count; i++) { - ch = bytes[i]; - if (ch == '%') { - int h = (bytes[i + 1] - '0'); - int l = (bytes[i + 2] - '0'); - if (h > 9) { - h -= 7; - } - if (l > 9) { - l -= 7; - } - bytes[length] = (byte)((h << 4) | l); - i += 2; - } else if (ch == '+') { - bytes[length] = ' '; - } else { - bytes[length] = bytes[i]; - } - length++; - } - return new String(bytes, 0, length, Charset.forName("UTF-8")); - - } - /* * TODO disabled this method globally. It is used in all the settings screens but I just * noticed that an unrelated icon was dimmed. Android must share drawables internally. diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java index 5743efed9..2577de515 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java @@ -1,6 +1,7 @@ package com.fsck.k9.mailstore.migrations; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -177,7 +178,7 @@ public class MigrationTo56 { String arguments = cursor.getString(2); command.arguments = arguments.split(","); for (int i = 0; i < command.arguments.length; i++) { - command.arguments[i] = Utility.fastUrlDecode(command.arguments[i]); + command.arguments[i] = fastUrlDecode(command.arguments[i]); } commands.add(command); } @@ -192,4 +193,33 @@ public class MigrationTo56 { public String command; public String[] arguments; } + + + private static String fastUrlDecode(String s) { + byte[] bytes = s.getBytes(Charset.forName("UTF-8")); + byte ch; + int length = 0; + for (int i = 0, count = bytes.length; i < count; i++) { + ch = bytes[i]; + if (ch == '%') { + int h = (bytes[i + 1] - '0'); + int l = (bytes[i + 2] - '0'); + if (h > 9) { + h -= 7; + } + if (l > 9) { + l -= 7; + } + bytes[length] = (byte)((h << 4) | l); + i += 2; + } else if (ch == '+') { + bytes[length] = ' '; + } else { + bytes[length] = bytes[i]; + } + length++; + } + return new String(bytes, 0, length, Charset.forName("UTF-8")); + } + }