Cleanup: use const args & variables, remove redundant checks

- Declare const variables & arguments.
- Remove redundant null checks.
- Remove break after return.
- Replace suspicious "&" with "&&".
This commit is contained in:
Campbell Barton
2024-04-15 09:44:27 +10:00
parent 740d1fbc4b
commit 49bf7ebbdd
21 changed files with 54 additions and 53 deletions

View File

@@ -93,7 +93,7 @@ bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT;
/**
* Attach a file with metrics information from memory.
*/
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size) ATTR_NONNULL(2);
void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2);
void BLF_aspect(int fontid, float x, float y, float z);
void BLF_position(int fontid, float x, float y, float z);
@@ -208,7 +208,7 @@ size_t BLF_width_to_rstrlen(int fontid,
void BLF_boundbox(int fontid,
const char *str,
size_t str_len,
rcti *box,
rcti *r_box,
ResultBLF *r_info = nullptr) ATTR_NONNULL(2);
/**

View File

@@ -214,7 +214,7 @@ int BLF_load_unique(const char *filepath)
return i;
}
void BLF_metrics_attach(int fontid, uchar *mem, int mem_size)
void BLF_metrics_attach(const int fontid, const uchar *mem, const int mem_size)
{
FontBLF *font = blf_get(fontid);

View File

@@ -709,7 +709,7 @@ static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
return false;
}
if (g && pen_x && !(font->flags & BLF_MONOSPACED)) {
if (!(font->flags & BLF_MONOSPACED)) {
*pen_x += blf_kerning(font, g_prev, g);
#ifdef BLF_SUBPIXEL_POSITION
@@ -953,7 +953,7 @@ float blf_font_height(FontBLF *font, const char *str, const size_t str_len, Resu
float blf_font_fixed_width(FontBLF *font)
{
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
const GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
float width = (gc) ? float(gc->fixed_width) : font->size / 2.0f;
blf_glyph_cache_release(font);
return width;
@@ -1226,15 +1226,15 @@ static void blf_font_boundbox_wrap_cb(FontBLF *font,
BLI_rcti_union(box, &box_single);
}
void blf_font_boundbox__wrap(
FontBLF *font, const char *str, const size_t str_len, rcti *box, ResultBLF *r_info)
FontBLF *font, const char *str, const size_t str_len, rcti *r_box, ResultBLF *r_info)
{
box->xmin = 32000;
box->xmax = -32000;
box->ymin = 32000;
box->ymax = -32000;
r_box->xmin = 32000;
r_box->xmax = -32000;
r_box->ymin = 32000;
r_box->ymax = -32000;
blf_font_wrap_apply(
font, str, str_len, font->wrap_width, r_info, blf_font_boundbox_wrap_cb, box);
font, str, str_len, font->wrap_width, r_info, blf_font_boundbox_wrap_cb, r_box);
}
/** Utility for #blf_font_draw_buffer__wrap. */
@@ -1444,7 +1444,7 @@ static void blf_font_metrics(FT_Face face, FontMetrics *metrics)
metrics->weight = 400;
metrics->width = 1.0f;
TT_OS2 *os2_table = (TT_OS2 *)FT_Get_Sfnt_Table(face, FT_SFNT_OS2);
const TT_OS2 *os2_table = (const TT_OS2 *)FT_Get_Sfnt_Table(face, FT_SFNT_OS2);
if (os2_table) {
/* The default (resting) font weight. */
if (os2_table->usWeightClass >= 1 && os2_table->usWeightClass <= 1000) {
@@ -1503,7 +1503,7 @@ static void blf_font_metrics(FT_Face face, FontMetrics *metrics)
}
/* The Post table usually contains a slant value, but in counter-clockwise degrees. */
TT_Postscript *post_table = (TT_Postscript *)FT_Get_Sfnt_Table(face, FT_SFNT_POST);
const TT_Postscript *post_table = (const TT_Postscript *)FT_Get_Sfnt_Table(face, FT_SFNT_POST);
if (post_table) {
if (post_table->italicAngle != 0) {
metrics->slant = float(post_table->italicAngle) / -65536.0f;
@@ -1787,10 +1787,9 @@ static FontBLF *blf_font_new_impl(const char *filepath,
blf_font_fill(font);
if (ft_library && ((FT_Library)ft_library != ft_lib)) {
font->ft_lib = (FT_Library)ft_library;
/* Pass. */
}
else {
font->ft_lib = ft_lib;
font->flags |= BLF_CACHED;
}
@@ -1821,7 +1820,7 @@ static FontBLF *blf_font_new_impl(const char *filepath,
}
/* Save TrueType table with bits to quickly test most unicode block coverage. */
TT_OS2 *os2_table = (TT_OS2 *)FT_Get_Sfnt_Table(font->face, FT_SFNT_OS2);
const TT_OS2 *os2_table = (const TT_OS2 *)FT_Get_Sfnt_Table(font->face, FT_SFNT_OS2);
if (os2_table) {
font->unicode_ranges[0] = uint(os2_table->ulUnicodeRange1);
font->unicode_ranges[1] = uint(os2_table->ulUnicodeRange2);

View File

@@ -881,7 +881,6 @@ static const FT_Var_Axis *blf_var_axis_by_tag(const FT_MM_Var *variations,
if (variations->axis[i].tag == tag) {
*r_axis_index = i;
return &(variations->axis)[i];
break;
}
}
return nullptr;
@@ -1152,7 +1151,7 @@ static bool blf_glyph_transform_monospace(FT_GlyphSlot glyph, int width)
{
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
FT_Fixed current = glyph->linearHoriAdvance;
FT_Fixed target = width << 16; /* Do math in 16.16 values. */
FT_Fixed target = FT_Fixed(width) << 16; /* Do math in 16.16 values. */
if (target < current) {
const FT_Pos embolden = (FT_Pos)((current - target) >> 13);
/* Horizontally widen strokes to counteract narrowing. */
@@ -1362,7 +1361,7 @@ static void blf_glyph_calc_rect_shadow(
/** \name Glyph Drawing
* \{ */
static void blf_texture_draw(GlyphBLF *g,
static void blf_texture_draw(const GlyphBLF *g,
const uchar color[4],
const int glyph_size[2],
const int x1,
@@ -1390,8 +1389,12 @@ static void blf_texture_draw(GlyphBLF *g,
}
}
static void blf_texture5_draw(
GlyphBLF *g, const uchar color_in[4], const int x1, const int y1, const int x2, const int y2)
static void blf_texture5_draw(const GlyphBLF *g,
const uchar color_in[4],
const int x1,
const int y1,
const int x2,
const int y2)
{
int glyph_size_flag[2];
/* flag the x and y component signs for 5x5 blurring */
@@ -1401,8 +1404,12 @@ static void blf_texture5_draw(
blf_texture_draw(g, color_in, glyph_size_flag, x1, y1, x2, y2);
}
static void blf_texture3_draw(
GlyphBLF *g, const uchar color_in[4], const int x1, const int y1, const int x2, const int y2)
static void blf_texture3_draw(const GlyphBLF *g,
const uchar color_in[4],
const int x1,
const int y1,
const int x2,
const int y2)
{
int glyph_size_flag[2];
/* flag the x component sign for 3x3 blurring */

View File

@@ -81,7 +81,7 @@ void blf_draw_buffer__start(FontBLF *font);
void blf_draw_buffer__end();
FontBLF *blf_font_new_from_filepath(const char *filepath);
FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, size_t mem_size);
FontBLF *blf_font_new_from_mem(const char *mem_name, const unsigned char *mem, size_t mem_size);
void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, size_t mem_size);
/**

View File

@@ -329,7 +329,7 @@ void BLI_filelist_entry_owner_to_string(const struct stat *st,
UNUSED_VARS(st);
BLI_strncpy(r_owner, "unknown", FILELIST_DIRENTRY_OWNER_LEN);
#else
passwd *pwuser = getpwuid(st->st_uid);
const passwd *pwuser = getpwuid(st->st_uid);
if (pwuser) {
BLI_strncpy(r_owner, pwuser->pw_name, sizeof(*r_owner) * FILELIST_DIRENTRY_OWNER_LEN);
@@ -422,7 +422,7 @@ void BLI_filelist_duplicate(direntry **dest_filelist,
*dest_filelist = static_cast<direntry *>(
MEM_mallocN(sizeof(**dest_filelist) * size_t(nrentries), __func__));
for (i = 0; i < nrentries; i++) {
direntry *const src = &src_filelist[i];
const direntry *src = &src_filelist[i];
direntry *dst = &(*dest_filelist)[i];
BLI_filelist_entry_duplicate(dst, src);
}

View File

@@ -210,20 +210,17 @@ void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src)
void BLI_memarena_clear(MemArena *ma)
{
if (ma->bufs) {
uchar *curbuf_prev;
size_t curbuf_used;
if (ma->bufs->next) {
memarena_buf_free_all(ma->bufs->next);
ma->bufs->next = NULL;
}
curbuf_prev = ma->curbuf;
const uchar *curbuf_prev = ma->curbuf;
ma->curbuf = ma->bufs->data;
memarena_curbuf_align(ma);
/* restore to original size */
curbuf_used = (size_t)(curbuf_prev - ma->curbuf);
const size_t curbuf_used = (size_t)(curbuf_prev - ma->curbuf);
ma->cursize += curbuf_used;
if (ma->use_calloc) {

View File

@@ -618,7 +618,8 @@ void BLI_mempool_as_array(BLI_mempool *pool, void *data)
{
const uint esize = pool->esize - (uint)POISON_REDZONE_SIZE;
BLI_mempool_iter iter;
char *elem, *p = data;
const char *elem;
char *p = data;
BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);

View File

@@ -63,7 +63,7 @@ static void sigbus_handler(int sig, siginfo_t *siginfo, void *ptr)
/* We only handle SIGBUS here for now. */
BLI_assert(sig == SIGBUS);
char *error_addr = (char *)siginfo->si_addr;
const char *error_addr = (const char *)siginfo->si_addr;
/* Find the file that this error belongs to. */
LISTBASE_FOREACH (LinkData *, link, &error_handler.open_mmaps) {
BLI_mmap_file *file = link->data;

View File

@@ -982,7 +982,7 @@ static const BChunkRef *table_lookup(const BArrayInfo *info,
if (cref->link->key == key)
# endif
{
BChunk *chunk_test = cref->link;
const BChunk *chunk_test = cref->link;
if (chunk_test->data_len <= size_left) {
if (bchunk_data_compare_unchecked(chunk_test, data, data_len, offset)) {
/* We could remove the chunk from the table, to avoid multiple hits. */
@@ -1176,7 +1176,7 @@ static BChunkList *bchunk_list_from_data_merge(const BArrayInfo *info,
while ((cref->prev != nullptr) && (cref != cref_match_first) &&
(cref->link->data_len <= data_len - i_prev))
{
BChunk *chunk_test = cref->link;
const BChunk *chunk_test = cref->link;
size_t offset = data_len - chunk_test->data_len;
if (bchunk_data_compare(chunk_test, data, data_len, offset)) {
data_len = offset;
@@ -1607,7 +1607,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs)
{
size_t size_total = 0;
BLI_mempool_iter iter;
BChunk *chunk;
const BChunk *chunk;
BLI_mempool_iternew(bs->memory.chunk, &iter);
while ((chunk = static_cast<BChunk *>(BLI_mempool_iterstep(&iter)))) {
BLI_assert(chunk->users > 0);

View File

@@ -52,7 +52,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count)
{
if (UNLIKELY(new_count > buffer->alloc_count)) {
if (buffer->flag & BLI_BUFFER_USE_STATIC) {
void *orig = buffer->data;
const void *orig = buffer->data;
buffer->data = buffer_alloc(buffer, new_count);
memcpy(buffer->data, orig, buffer->elem_size * buffer->count);

View File

@@ -2311,7 +2311,7 @@ static bool bvhtreeverlap_cmp(const BVHTreeOverlap &a, const BVHTreeOverlap &b)
if (a.indexA < b.indexA) {
return true;
}
if ((a.indexA == b.indexA) & (a.indexB < b.indexB)) {
if ((a.indexA == b.indexA) && (a.indexB < b.indexB)) {
return true;
}
return false;

View File

@@ -107,8 +107,7 @@ static void fill_locales()
if (num_locales > 0) {
locales = static_cast<const char **>(MEM_callocN(num_locales * sizeof(char *), __func__));
while (line) {
int id;
char *loc, *sep1, *sep2, *sep3;
const char *loc, *sep1, *sep2, *sep3;
str = (char *)line->link;
if (ELEM(str[0], '#', '\0')) {
@@ -116,7 +115,7 @@ static void fill_locales()
continue;
}
id = atoi(str);
const int id = atoi(str);
sep1 = strchr(str, ':');
if (sep1) {
sep1++;

View File

@@ -241,7 +241,7 @@ static void icon_merge_context_init(IconMergeContext *context)
* Is used to check whether icon is re-defined, and to provide useful information about which
* files are conflicting. */
static IconInfo *icon_merge_context_info_for_icon_head(IconMergeContext *context,
IconHead *icon_head)
const IconHead *icon_head)
{
if (context->read_icons == nullptr) {
return nullptr;

View File

@@ -44,7 +44,7 @@ DebugDraw::DebugDraw()
for (auto edge : IndexRange(circle_resolution)) {
for (auto vert : IndexRange(2)) {
const float angle = (2 * M_PI) * (edge + vert) / float(circle_resolution);
float point[3] = {cosf(angle), sinf(angle), 0.0f};
const float point[3] = {cosf(angle), sinf(angle), 0.0f};
sphere_verts_.append(
float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3]));
}
@@ -56,7 +56,7 @@ DebugDraw::DebugDraw()
for (auto edge : IndexRange(point_resolution)) {
for (auto vert : IndexRange(2)) {
const float angle = (2 * M_PI) * (edge + vert) / float(point_resolution);
float point[3] = {cosf(angle), sinf(angle), 0.0f};
const float point[3] = {cosf(angle), sinf(angle), 0.0f};
point_verts_.append(
float3(point[(0 + axis) % 3], point[(1 + axis) % 3], point[(2 + axis) % 3]));
}

View File

@@ -302,7 +302,7 @@ static bool annotation_stroke_filtermval(tGPsdata *p, const float mval[2], const
static void annotation_stroke_convertcoords(tGPsdata *p,
const float mval[2],
float out[3],
float *depth)
const float *depth)
{
bGPdata *gpd = p->gpd;
if (depth && (*depth == DEPTH_INVALID)) {

View File

@@ -363,7 +363,6 @@ static uchar *colormanage_cache_get(ImBuf *ibuf,
cache_ibuf = colormanage_cache_get_ibuf(ibuf, &key, cache_handle);
if (cache_ibuf) {
ColormanageCacheData *cache_data;
BLI_assert(cache_ibuf->x == ibuf->x && cache_ibuf->y == ibuf->y);
@@ -374,7 +373,7 @@ static uchar *colormanage_cache_get(ImBuf *ibuf,
* check here which exposure/gamma/curve was used for cached buffer and if they're
* different from requested buffer should be re-generated
*/
cache_data = colormanage_cachedata_get(cache_ibuf);
const ColormanageCacheData *cache_data = colormanage_cachedata_get(cache_ibuf);
if (cache_data->look != view_settings->look ||
cache_data->exposure != view_settings->exposure ||

View File

@@ -355,7 +355,7 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
uint i, i_next, w, h, planes;
uint y;
int *r, *g, *b, *a; /* matching 'opj_image_comp.data' type */
const int *r, *g, *b, *a; /* matching 'opj_image_comp.data' type */
opj_dparameters_t parameters; /* decompression parameters */

View File

@@ -118,7 +118,6 @@ ImBuf *IMB_ibImageFromMemory(
ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
{
ImBuf *ibuf;
uchar *mem;
if (file == -1) {
return nullptr;
@@ -132,7 +131,7 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
return nullptr;
}
mem = static_cast<uchar *>(BLI_mmap_get_pointer(mmap_file));
const uchar *mem = static_cast<const uchar *>(BLI_mmap_get_pointer(mmap_file));
const size_t size = BLI_mmap_get_length(mmap_file);
ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr);

View File

@@ -1420,7 +1420,7 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
}
/** Useful function when debugging the reconstruct steps. */
[[maybe_unused]] static void print_reconstruct_step(ReconstructStep *step,
[[maybe_unused]] static void print_reconstruct_step(const ReconstructStep *step,
const SDNA *oldsdna,
const SDNA *newsdna)
{

View File

@@ -441,10 +441,10 @@ static void deform_verts(ModifierData *md,
void BKE_modifier_mdef_compact_influences(ModifierData *md)
{
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
float weight, *weights, totweight;
float weight, totweight;
int influences_num, verts_num, cage_verts_num, a, b;
weights = mmd->bindweights;
const float *weights = mmd->bindweights;
if (!weights) {
return;
}