]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Use the branch prediction macros in potentially hot code
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 11:02:09 +0000 (11:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 11:02:09 +0000 (11:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c

index 51e877bbcbc2d359c679d4677460b06bf501a65f..4bc41a6dda60522dea909d42f4ae870ff125443d 100644 (file)
@@ -108,7 +108,7 @@ static ssize_t archive_file_read(struct archive* a, void* data, const void** buf
        // Read a block of data into the buffer
        size_t bytes_read = fread(file->buffer, 1, sizeof(file->buffer), file->f);
 
-       if (bytes_read < sizeof(file->buffer) && ferror(file->f)) {
+       if (unlikely(bytes_read < sizeof(file->buffer) && ferror(file->f))) {
                archive_set_error(a, errno, "Error reading file");
        }
 
@@ -123,11 +123,11 @@ static int64_t archive_file_skip(struct archive* a, void* data, off_t skip) {
        int r;
 
        // Skip if we don't support seek
-       if (file->flags & PAKFIRE_ARCHIVE_FILE_CANT_SEEK)
+       if (unlikely(file->flags & PAKFIRE_ARCHIVE_FILE_CANT_SEEK))
                return 0;
 
        // Skip if we have been asked to do nothing
-       if (skip == 0)
+       if (unlikely(skip == 0))
                return 0;
 
        // Perform seek()
@@ -606,7 +606,7 @@ static int __pakfire_archive_read_metadata(struct pakfire_archive* archive,
        }
 
        // Format >= 6
-       if (archive->format >= 6) {
+       if (likely(archive->format >= 6)) {
                // Parse PKGINFO
                if (strcmp(path, ".PKGINFO") == 0) {
                        r = pakfire_archive_parse_json_metadata(archive, data, length);
@@ -642,7 +642,7 @@ static int __pakfire_archive_filter_metadata(struct pakfire_archive* archive,
        const char* path = archive_entry_pathname(entry);
 
        // Format >= 6
-       if (archive->format >= 6) {
+       if (likely(archive->format >= 6)) {
                // Anything that starts with "." is a metadata file
                if (*path == '.')
                        return PAKFIRE_WALK_OK;