0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

NF: Quicker split field

The function split is optimized for splitting around a char. We never used it because instead we used unicode encoding
in regexp. This small change will save plenty of time for all batch processing.
This commit is contained in:
Arthur Milchior 2020-10-23 11:35:36 +02:00 committed by Mike Hardy
parent 1d618f7243
commit 84f1d231ad
4 changed files with 8 additions and 3 deletions

View File

@ -149,4 +149,6 @@ public class Consts {
public static final long DEFAULT_DECK_ID = 1;
/** Default dconf - can't be removed */
public static final long DEFAULT_DECK_CONFIG_ID = 1;
public static final String FIELD_SEPARATOR = Character.toString('\u001f');
}

View File

@ -71,6 +71,8 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import androidx.annotation.Nullable;
import timber.log.Timber;
import static com.ichi2.libanki.Consts.FIELD_SEPARATOR;
@SuppressWarnings({"PMD.AvoidThrowingRawExceptionTypes","PMD.AvoidReassigningParameters",
"PMD.MethodNamingConventions","PMD.FieldDeclarationsShouldBeAtStartOfClass"})
public class Utils {
@ -545,7 +547,7 @@ public class Utils {
public static String[] splitFields(String fields) {
// -1 ensures that we don't drop empty fields at the ends
return fields.split("\\x1f", -1);
return fields.split(FIELD_SEPARATOR, -1);
}
/*

View File

@ -231,7 +231,7 @@ public class FlashCardsContract {
* <td>String</td>
* <td>{@link #FLDS}</td>
* <td>read-write</td>
* <td>Fields of this note. Fields are separated by "\\x1f"</td>
* <td>Fields of this note. Fields are separated by "\\x1f", a.k.a. Consts.FIELD_SEPARATOR</td>
* </tr>
* <tr>
* <td>long</td>

View File

@ -36,6 +36,7 @@ class Utils {
private static final Pattern tagPattern = Pattern.compile("<.*?>");
private static final Pattern imgPattern = Pattern.compile("<img src=[\"']?([^\"'>]+)[\"']? ?/?>");
private static final Pattern htmlEntitiesPattern = Pattern.compile("&#?\\w+;");
private static final String FIELD_SEPARATOR = Character.toString('\u001f');
static String joinFields(String[] list) {
@ -44,7 +45,7 @@ class Utils {
static String[] splitFields(String fields) {
return fields != null? fields.split("\\x1f", -1): null;
return fields != null? fields.split(FIELD_SEPARATOR, -1): null;
}
static String joinTags(Set<String> tags) {