]> diplodocus.org Git - nmh/commitdiff
Stop one lseek(2) per header fetched by m_getfld.c in common case.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 07:23:51 +0000 (08:23 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 07:23:51 +0000 (08:23 +0100)
Only call ftello(3) in enter_getfld() when track_filepos has been
requested;  not often.

sbr/m_getfld.c

index 4da2f3eeb34c8fd93fb8e2527b7331a7f5a40d22..531381d8d8f556abd3f8d12b6553149d334e8550 100644 (file)
@@ -347,7 +347,7 @@ void m_getfld_state_destroy (m_getfld_state_t *gstate) {
 static void
 enter_getfld (m_getfld_state_t *gstate, FILE *iob) {
     m_getfld_state_t s;
-    off_t pos = ftello (iob);
+    off_t pos;
 
     if (! *gstate) {
        m_getfld_state_init (gstate, iob);
@@ -363,7 +363,11 @@ enter_getfld (m_getfld_state_t *gstate, FILE *iob) {
        readpos shift code being currently unused. */
     s->iob = iob;
 
-    if (s->track_filepos  &&  (pos != 0  ||  s->last_internal_pos != 0)) {
+    if (!s->track_filepos)
+        return;
+
+    pos = ftello(iob);
+    if (pos != 0  ||  s->last_internal_pos != 0) {
        if (s->last_internal_pos == 0) {
            s->total_bytes_read = pos;
        } else {