mozilla-services/android-sync — comment on commit 626d8a79f0fa0bb8e537eb7d0557280d7dd1efa9
File: src/main/java/org/mozilla/gecko/sync/repositories/android/RepoUtils.java line 186
By rnewman:

You could move the `logLabel` logic (and even the `queryEnd` computation, if you wish) into a separate method:

```
private Cursor checkAndLogCursor(String label, long queryStart, Cursor c) {
long queryEnd = android.os.SystemClock.uptimeMillis();
String logLabel = (label == null) ? this.tag : this.tag + label;
RepoUtils.queryTimeLogger(logLabel, queryStart, queryEnd);
return checkNullCursor(label, c);
}
```

so `safeQuery`'s body becomes:

```
long queryStart = android.os.SystemClock.uptimeMillis();
Cursor c = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
checkAndLogCursor(label, queryStart, c);
```

which of course you could flatten into a single line, because Java guarantees order of evaluation.

Note also that checkNullCursor wants to concatenate the tag and the label, so you should shuffle the internals of `checkAndLogCursor` to reuse `logLabel`.

We can't do better than this: we can't push `queryStart` anywhere else, and we can't abstract the cursor creation in the two methods without introducing another layer (such as a `Runnable` to delay execution).