gggard / AndroidCaldavSyncAdapater

Caldav synch adapter for Android
246 stars 88 forks source link

Use EntityUtils.toString() as a faster way to get entity content #188

Open Griffon26 opened 10 years ago

Griffon26 commented 10 years ago

While debugging a different issue I noticed that extracting the content from an entity was done by concatenating to a string line by line. This was causing a realloc of everything up to that point each time through the loop and was taking a lot of time for the initial sync of a calendar with a lot of items. I aborted a measurement of the original code after 10 minutes. The new code did it in 5 seconds.

I replaced three instances of this type of string concatenation with EntityUtils.toString(), which turned out to be more or less equal in speed to using a StringWriter or a StringBuilder, but is much fewer lines of code.