Skip to content

Commit

Permalink
Inline small functions to greatly improve performance
Browse files Browse the repository at this point in the history
Lots of small functions being defined in extra files meaningfully
increases runtime without link-time-optimization being enabled.
C11 supports marking functions as `inline` which sereves both as a hint
to the compiler as well as allowing definition inside the header.
  • Loading branch information
Hannes Franke committed Jul 11, 2024
1 parent a2eaa94 commit a572329
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 365 deletions.
16 changes: 1 addition & 15 deletions imageprocess/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
//
// SPDX-License-Identifier: GPL-2.0-only

#include <libavutil/frame.h>

#include "imageprocess/blit.h"
#include "imageprocess/image.h"
#include "imageprocess/pixel.h"
#include "imageprocess/blit.h"
#include "lib/logging.h"
#include "lib/math_util.h"

Expand Down Expand Up @@ -55,17 +52,6 @@ Image create_compatible_image(Image source, RectangleSize size, bool fill) {
source.abs_black_threshold);
}

RectangleSize size_of_image(Image image) {
return (RectangleSize){
.width = image.frame->width,
.height = image.frame->height,
};
}

Rectangle full_image(Image image) {
return rectangle_from_size(POINT_ORIGIN, size_of_image(image));
}

Rectangle clip_rectangle(Image image, Rectangle area) {
Rectangle normal_area = normalize_rectangle(area);

Expand Down
17 changes: 13 additions & 4 deletions imageprocess/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#pragma once

#include "imageprocess/primitives.h"
#include <libavutil/frame.h>

typedef struct AVFrame AVFrame;
#include "imageprocess/primitives.h"

typedef struct {
AVFrame *frame;
Expand All @@ -23,6 +23,15 @@ void replace_image(Image *image, Image *new_image);
void free_image(Image *image);
Image create_compatible_image(Image source, RectangleSize size, bool fill);

RectangleSize size_of_image(Image image);
Rectangle full_image(Image image);
inline RectangleSize size_of_image(Image image) {
return (RectangleSize){
.width = image.frame->width,
.height = image.frame->height,
};
}

inline Rectangle full_image(Image image) {
return rectangle_from_size(POINT_ORIGIN, size_of_image(image));
}

Rectangle clip_rectangle(Image image, Rectangle area);
172 changes: 0 additions & 172 deletions imageprocess/pixel.c

This file was deleted.

Loading

0 comments on commit a572329

Please sign in to comment.