summaryrefslogtreecommitdiffstats
path: root/icu/src/main/native
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-01-13 23:14:56 -0800
committerElliott Hughes <enh@google.com>2010-01-14 12:50:53 -0800
commite1e5e8e60af12f145c4dd0395e30069665f97529 (patch)
tree191a722e9ccb999bf9eec8d162abc540f409fa8e /icu/src/main/native
parentb64c406bd2becd117d88cef3d90d84243d6016af (diff)
downloadlibcore-e1e5e8e60af12f145c4dd0395e30069665f97529.zip
libcore-e1e5e8e60af12f145c4dd0395e30069665f97529.tar.gz
libcore-e1e5e8e60af12f145c4dd0395e30069665f97529.tar.bz2
Fix Date.toString.
Date.toString was using the TimeZone id ("America/Los_Angeles") rather than the time zone short name ("PDT" or "PST", depending on time of year). The naive fix made things 5x slower, so I improved Resources.getDisplayTimeZone so the fixed Date.toString is only 2x slower. This could be improved further with a faster getDisplayTimeZone. I hoped to replace the body of Date.toString with a call to SimpleDateFormat, but that turns out to be 40x slower. This patch also optimizes SimpleDateFormat to bring the gap down to 8x by using Resources.getDisplayTimeZone instead of asking for all the strings. (Note that these improvements refer to the hopefully common case of localized strings for the default locale. If you have the misfortune to need strings for other locales, the new code will be more like 600x faster. At 0.5s a call on the fastest current hardware, I hope no-one's actually doing that. Dalvik Explorer -- available on the Market -- needs to do it when generating summary reports, and it is indeed ridiculously slow. It uses two SimpleDateFormat objects per locale, so it takes 1s per locale, for about 60 locales. I've tested Dalvik Explorer with this patch, and it does fix that pathological behavior.) Also fix a bug I introduced in https://android-git.corp.google.com/g/36242 that meant that our zone names String[][] contained incorrect values (accidentally concatenating each successive value in a row), found by existing tests now we use more of those values. Also replace a couple of "new Integer" calls with Integer.valueOf for a modest speedup. Also factor out some duplication. Bug: http://code.google.com/p/android/issues/detail?id=6013
Diffstat (limited to 'icu/src/main/native')
-rw-r--r--icu/src/main/native/ResourceInterface.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/icu/src/main/native/ResourceInterface.cpp b/icu/src/main/native/ResourceInterface.cpp
index 151b23e..3cb4224 100644
--- a/icu/src/main/native/ResourceInterface.cpp
+++ b/icu/src/main/native/ResourceInterface.cpp
@@ -252,6 +252,12 @@ static TimeZone* timeZoneFromId(JNIEnv* env, jstring id) {
return TimeZone::createTimeZone(zoneID);
}
+static jstring formatDate(JNIEnv* env, const SimpleDateFormat& fmt, const UDate& when) {
+ UnicodeString str;
+ fmt.format(when, str);
+ return env->NewString(str.getBuffer(), str.length());
+}
+
static void getTimeZonesNative(JNIEnv* env, jclass clazz,
jobjectArray outerArray, jstring locale) {
@@ -304,24 +310,19 @@ static void getTimeZonesNative(JNIEnv* env, jclass clazz,
daylightSavingDate = date2;
}
- UnicodeString str;
- shortFormat.format(daylightSavingDate, str);
- jstring content = env->NewString(str.getBuffer(), str.length());
+ jstring content = formatDate(env, shortFormat, daylightSavingDate);
env->SetObjectArrayElement(shortDlTimeArray, i, content);
env->DeleteLocalRef(content);
- shortFormat.format(standardDate, str);
- content = env->NewString(str.getBuffer(), str.length());
+ content = formatDate(env, shortFormat, standardDate);
env->SetObjectArrayElement(shortStdTimeArray, i, content);
env->DeleteLocalRef(content);
- longFormat.format(daylightSavingDate, str);
- content = env->NewString(str.getBuffer(), str.length());
+ content = formatDate(env, longFormat, daylightSavingDate);
env->SetObjectArrayElement(longDlTimeArray, i, content);
env->DeleteLocalRef(content);
- longFormat.format(standardDate, str);
- content = env->NewString(str.getBuffer(), str.length());
+ content = formatDate(env, longFormat, standardDate);
env->SetObjectArrayElement(longStdTimeArray, i, content);
env->DeleteLocalRef(content);