move legacy utility method into migration class
This commit is contained in:
parent
d6c50b4db6
commit
902506b2b8
2 changed files with 31 additions and 35 deletions
|
@ -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.
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue