Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add itoa(), replace snprintf("%d") calls

we can save some space and still end up with a 20% faster function

Change-Id: Ia58900122944b8527ef01a673afe18ea794acb41

authored by

William Wilgus and committed by
William Wilgus
f55fe21f 9e61d53c

+98 -41
+31 -31
apps/gui/skin_engine/skin_tokens.c
··· 256 256 if (id3->disc_string) 257 257 return id3->disc_string; 258 258 if (id3->discnum) { 259 - snprintf(buf, buf_size, "%d", id3->discnum); 259 + itoa(buf, buf_size, id3->discnum); 260 260 return buf; 261 261 } 262 262 return NULL; ··· 264 264 if (id3->track_string) 265 265 return id3->track_string; 266 266 if (id3->tracknum) { 267 - snprintf(buf, buf_size, "%d", id3->tracknum); 267 + itoa(buf, buf_size, id3->tracknum); 268 268 return buf; 269 269 } 270 270 return NULL; ··· 291 291 if( id3->year_string ) 292 292 return id3->year_string; 293 293 if (id3->year) { 294 - snprintf(buf, buf_size, "%d", id3->year); 294 + itoa(buf, buf_size, id3->year); 295 295 return buf; 296 296 } 297 297 return NULL; ··· 299 299 return id3->comment; 300 300 case SKIN_TOKEN_FILE_BITRATE: 301 301 if(id3->bitrate) 302 - snprintf(buf, buf_size, "%d", id3->bitrate); 302 + itoa(buf, buf_size, id3->bitrate); 303 303 else 304 304 return "?"; 305 305 return buf; ··· 360 360 return get_codectype(id3); 361 361 362 362 case SKIN_TOKEN_FILE_FREQUENCY: 363 - snprintf(buf, buf_size, "%ld", id3->frequency); 363 + itoa(buf, buf_size, id3->frequency); 364 364 return buf; 365 365 case SKIN_TOKEN_FILE_FREQUENCY_KHZ: 366 366 /* ignore remainders < 100, so 22050 Hz becomes just 22k */ 367 367 if ((id3->frequency % 1000) < 100) 368 - snprintf(buf, buf_size, "%ld", id3->frequency / 1000); 368 + itoa(buf, buf_size, id3->frequency / 1000); 369 369 else 370 370 snprintf(buf, buf_size, "%ld.%lu", 371 371 id3->frequency / 1000, ··· 374 374 case SKIN_TOKEN_FILE_VBR: 375 375 return (id3->vbr) ? "(avg)" : NULL; 376 376 case SKIN_TOKEN_FILE_SIZE: 377 - snprintf(buf, buf_size, "%ld", id3->filesize / 1024); 377 + itoa(buf, buf_size, id3->filesize / 1024); 378 378 return buf; 379 379 380 380 #ifdef HAVE_TAGCACHE 381 381 case SKIN_TOKEN_DATABASE_PLAYCOUNT: 382 382 if (intval) 383 383 *intval = id3->playcount + 1; 384 - snprintf(buf, buf_size, "%ld", id3->playcount); 384 + itoa(buf, buf_size, id3->playcount); 385 385 return buf; 386 386 case SKIN_TOKEN_DATABASE_RATING: 387 387 if (intval) 388 388 *intval = id3->rating + 1; 389 - snprintf(buf, buf_size, "%d", id3->rating); 389 + itoa(buf, buf_size, id3->rating); 390 390 return buf; 391 391 case SKIN_TOKEN_DATABASE_AUTOSCORE: 392 392 if (intval) 393 393 *intval = id3->score + 1; 394 - snprintf(buf, buf_size, "%d", id3->score); 394 + itoa(buf, buf_size, id3->score); 395 395 return buf; 396 396 #endif 397 397 ··· 473 473 region_data->freq_step, buf, buf_size); 474 474 #ifdef HAVE_RADIO_RSSI 475 475 case SKIN_TOKEN_TUNER_RSSI: 476 - snprintf(buf, buf_size, "%d",tuner_get(RADIO_RSSI)); 476 + itoa(buf, buf_size,tuner_get(RADIO_RSSI)); 477 477 if (intval) 478 478 { 479 479 int val = tuner_get(RADIO_RSSI); ··· 490 490 } 491 491 return buf; 492 492 case SKIN_TOKEN_TUNER_RSSI_MIN: 493 - snprintf(buf, buf_size, "%d",tuner_get(RADIO_RSSI_MIN)); 493 + itoa(buf, buf_size,tuner_get(RADIO_RSSI_MIN)); 494 494 return buf; 495 495 case SKIN_TOKEN_TUNER_RSSI_MAX: 496 - snprintf(buf, buf_size, "%d",tuner_get(RADIO_RSSI_MAX)); 496 + itoa(buf, buf_size,tuner_get(RADIO_RSSI_MAX)); 497 497 return buf; 498 498 #endif 499 499 case SKIN_TOKEN_PRESET_NAME: ··· 515 515 format_freq_MHz(radio_get_preset_freq(preset), 516 516 region_data->freq_step, buf, buf_size); 517 517 else 518 - snprintf(buf, buf_size, "%d", preset + 1); 518 + itoa(buf, buf_size, preset + 1); 519 519 return buf; 520 520 } 521 521 case SKIN_TOKEN_PRESET_COUNT: 522 - snprintf(buf, buf_size, "%d", radio_preset_count()); 522 + itoa(buf, buf_size, radio_preset_count()); 523 523 if (intval) 524 524 *intval = radio_preset_count(); 525 525 return buf; ··· 777 777 778 778 779 779 case SKIN_TOKEN_RTC_12HOUR_CFG: 780 - snprintf(buf, buf_size, "%d", global_settings.timeformat); 780 + itoa(buf, buf_size, global_settings.timeformat); 781 781 numeric_ret = global_settings.timeformat + 1; 782 782 break; 783 783 case SKIN_TOKEN_RTC_DAY_OF_MONTH: ··· 1110 1110 1111 1111 case SKIN_TOKEN_PLAYLIST_ENTRIES: 1112 1112 numeric_ret = playlist_amount(); 1113 - snprintf(buf, buf_size, "%d", numeric_ret); 1113 + itoa(buf, buf_size, numeric_ret); 1114 1114 numeric_buf = buf; 1115 1115 goto gtv_ret_numeric_tag_info; 1116 1116 case SKIN_TOKEN_LIST_TITLE_TEXT: 1117 1117 return sb_get_title(gwps->display->screen_type); 1118 1118 case SKIN_TOKEN_LIST_TITLE_ICON: 1119 1119 numeric_ret = sb_get_icon(gwps->display->screen_type); 1120 - snprintf(buf, buf_size, "%d", numeric_ret); 1120 + itoa(buf, buf_size, numeric_ret); 1121 1121 numeric_buf = buf; 1122 1122 goto gtv_ret_numeric_tag_info; 1123 1123 case SKIN_TOKEN_LIST_ITEM_TEXT: ··· 1128 1128 } 1129 1129 case SKIN_TOKEN_LIST_ITEM_ROW: 1130 1130 numeric_ret = skinlist_get_item_row() + 1; 1131 - snprintf(buf, buf_size, "%d", numeric_ret); 1131 + itoa(buf, buf_size, numeric_ret); 1132 1132 numeric_buf = buf; 1133 1133 goto gtv_ret_numeric_tag_info; 1134 1134 case SKIN_TOKEN_LIST_ITEM_COLUMN: 1135 1135 numeric_ret = skinlist_get_item_column() + 1; 1136 - snprintf(buf, buf_size, "%d", numeric_ret); 1136 + itoa(buf, buf_size, numeric_ret); 1137 1137 numeric_buf = buf; 1138 1138 goto gtv_ret_numeric_tag_info; 1139 1139 case SKIN_TOKEN_LIST_ITEM_NUMBER: 1140 1140 numeric_ret = skinlist_get_item_number() + 1; 1141 - snprintf(buf, buf_size, "%d", numeric_ret); 1141 + itoa(buf, buf_size, numeric_ret); 1142 1142 numeric_buf = buf; 1143 1143 goto gtv_ret_numeric_tag_info; 1144 1144 case SKIN_TOKEN_LIST_ITEM_IS_SELECTED: ··· 1149 1149 if (!li) return NULL; 1150 1150 int icon = skinlist_get_item_icon(li->offset, li->wrap); 1151 1151 numeric_ret = icon; 1152 - snprintf(buf, buf_size, "%d", numeric_ret); 1152 + itoa(buf, buf_size, numeric_ret); 1153 1153 numeric_buf = buf; 1154 1154 goto gtv_ret_numeric_tag_info; 1155 1155 } ··· 1160 1160 1161 1161 case SKIN_TOKEN_PLAYLIST_POSITION: 1162 1162 numeric_ret = playlist_get_display_index()+offset; 1163 - snprintf(buf, buf_size, "%d", numeric_ret); 1163 + itoa(buf, buf_size, numeric_ret); 1164 1164 numeric_buf = buf; 1165 1165 goto gtv_ret_numeric_tag_info; 1166 1166 ··· 1248 1248 } 1249 1249 1250 1250 if (l > -1) { 1251 - snprintf(buf, buf_size, "%d", l); 1251 + itoa(buf, buf_size, l); 1252 1252 numeric_buf = buf; 1253 1253 goto gtv_ret_numeric_tag_info; 1254 1254 } else { ··· 1327 1327 break; 1328 1328 } 1329 1329 1330 - snprintf(buf, buf_size, "%d", numeric_ret-1); 1330 + itoa(buf, buf_size, numeric_ret-1); 1331 1331 numeric_buf = buf; 1332 1332 goto gtv_ret_numeric_tag_info; 1333 1333 } 1334 1334 1335 1335 case SKIN_TOKEN_REPEAT_MODE: 1336 - snprintf(buf, buf_size, "%d", global_settings.repeat_mode); 1336 + itoa(buf, buf_size, global_settings.repeat_mode); 1337 1337 numeric_ret = global_settings.repeat_mode + 1; 1338 1338 numeric_buf = buf; 1339 1339 goto gtv_ret_numeric_tag_info; ··· 1354 1354 left : right; 1355 1355 val = peak_meter_scale_value(val, limit==1 ? MAX_PEAK : limit); 1356 1356 numeric_ret = val; 1357 - snprintf(buf, buf_size, "%d", numeric_ret); 1357 + itoa(buf, buf_size, numeric_ret); 1358 1358 data->peak_meter_enabled = true; 1359 1359 numeric_buf = buf; 1360 1360 goto gtv_ret_numeric_tag_info; ··· 1362 1362 1363 1363 case SKIN_TOKEN_CROSSFADE: 1364 1364 #ifdef HAVE_CROSSFADE 1365 - snprintf(buf, buf_size, "%d", global_settings.crossfade); 1365 + itoa(buf, buf_size, global_settings.crossfade); 1366 1366 numeric_ret = global_settings.crossfade + 1; 1367 1367 #else 1368 - snprintf(buf, buf_size, "%d", 0); 1368 + itoa(buf, buf_size, 0); 1369 1369 #endif 1370 1370 numeric_buf = buf; 1371 1371 goto gtv_ret_numeric_tag_info; ··· 1753 1753 { 1754 1754 int curr_screen = get_current_activity(); 1755 1755 numeric_ret = curr_screen; 1756 - snprintf(buf, buf_size, "%d", numeric_ret); 1756 + itoa(buf, buf_size, numeric_ret); 1757 1757 numeric_buf = buf; 1758 1758 goto gtv_ret_numeric_tag_info; 1759 1759 } ··· 1767 1767 char *skin_base = get_skin_buffer(data); 1768 1768 struct skin_var* var = SKINOFFSETTOPTR(skin_base, token->value.data); 1769 1769 numeric_ret = var->value; 1770 - snprintf(buf, buf_size, "%d", numeric_ret); 1770 + itoa(buf, buf_size, numeric_ret); 1771 1771 numeric_buf = buf; 1772 1772 goto gtv_ret_numeric_tag_info; 1773 1773 }
+2 -2
apps/gui/statusbar.c
··· 18 18 * KIND, either express or implied. 19 19 * 20 20 ****************************************************************************/ 21 - 22 21 #include <stdio.h> 23 22 #include "config.h" 24 23 #include "font.h" 25 24 #include "kernel.h" 26 25 #include "string.h" /* for memcmp oO*/ 26 + #include "string-extra.h" /* for itoa */ 27 27 #include "sound.h" 28 28 #include "settings.h" 29 29 #include "viewport.h" ··· 611 611 int x, int y) 612 612 { 613 613 char buf[12], *ptr; 614 - snprintf(buf, sizeof(buf), "%d", value); 614 + itoa(buf, sizeof(buf), value); 615 615 616 616 for (ptr = buf; *ptr != '\0'; ptr++, x += BM_GLYPH_WIDTH) 617 617 display->mono_bitmap(bitmap_glyphs_4x8[*ptr - '0'], x, y,
+4 -4
apps/screens.c
··· 519 519 case LANG_TAGNAVI_ALL_TRACKS: 520 520 if (info->track_ct <= 1) 521 521 return NULL; 522 - snprintf(buffer, buffer_len, "%d", info->track_ct); 522 + itoa(buffer, buffer_len, info->track_ct); 523 523 val = buffer; 524 524 if(say_it) 525 525 talk_number(info->track_ct, true); ··· 558 558 } 559 559 else if (id3->discnum) 560 560 { 561 - snprintf(buffer, buffer_len, "%d", id3->discnum); 561 + itoa(buffer, buffer_len, id3->discnum); 562 562 val = buffer; 563 563 if(say_it) 564 564 talk_number(id3->discnum, true); ··· 573 573 } 574 574 else if (id3->tracknum) 575 575 { 576 - snprintf(buffer, buffer_len, "%d", id3->tracknum); 576 + itoa(buffer, buffer_len, id3->tracknum); 577 577 val = buffer; 578 578 if(say_it) 579 579 talk_number(id3->tracknum, true); ··· 602 602 } 603 603 else if (id3->year) 604 604 { 605 - snprintf(buffer, buffer_len, "%d", id3->year); 605 + itoa(buffer, buffer_len, id3->year); 606 606 val = buffer; 607 607 if(say_it) 608 608 talk_value(id3->year, UNIT_DATEYEAR, true);
+1 -1
apps/settings.c
··· 456 456 break; /* we got a value */ 457 457 } 458 458 459 - snprintf(buf, buf_len, "%d", *(int*)setting->setting); 459 + itoa(buf, buf_len, *(int*)setting->setting); 460 460 break; 461 461 case F_T_BOOL: 462 462 cfg_int_to_string(setting, *(bool*)setting->setting, buf, buf_len);
+1 -1
apps/settings_list.c
··· 806 806 static char* volume_limit_write_to_cfg(void* setting, char*buf, int buf_len) 807 807 { 808 808 int current = *(int*)setting; 809 - snprintf(buf, buf_len, "%d", current); 809 + itoa(buf, buf_len, current); 810 810 return buf; 811 811 } 812 812 static bool volume_limit_is_changed(void* setting, void* defaultval)
+11 -2
apps/tagcache.c
··· 239 239 #define logf_clauses logf 240 240 #endif /* ndef LOGF_ENABLE */ 241 241 242 + #if !defined(itoa) 243 + char *itoa(char *buf, size_t bufsz, long int i) 244 + { 245 + snprintf(buf, bufsz, "%ld", i); 246 + return buf; 247 + } 248 + #endif 249 + 250 + 242 251 /* Status information of the tagcache. */ 243 252 static struct tagcache_stat tc_stat; 244 253 ··· 1912 1921 1913 1922 if (is_numeric) 1914 1923 { 1915 - snprintf(buf, bufsz, "%ld", tcs->position); 1924 + itoa(buf, bufsz, tcs->position); 1916 1925 tcs->result = buf; 1917 1926 tcs->result_len = strlen(buf) + 1; 1918 1927 return true; ··· 3982 3991 { 3983 3992 if (TAGCACHE_IS_NUMERIC(j)) 3984 3993 { 3985 - snprintf(temp, sizeof temp, "%d", (int)idx.tag_seek[j]); 3994 + itoa(temp, sizeof temp, (int)idx.tag_seek[j]); 3986 3995 write_tag(clfd, tagcache_tag_to_str(j), temp); 3987 3996 continue; 3988 3997 }
+1
firmware/SOURCES
··· 219 219 #ifndef BOOTLOADER 220 220 chunk_alloc.c 221 221 common/strptokspn.c 222 + common/itoa.c 222 223 common/ap_int.c 223 224 #endif 224 225 common/version.c
+45
firmware/common/itoa.c
··· 1 + #include <stddef.h> 2 + #include "string.h" 3 + #include "strmemccpy.h" 4 + /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 5 + Written by James Clark (jjc@jclark.com) 6 + 7 + This file was part of groff. 8 + 9 + groff is free software; you can redistribute it and/or modify it under 10 + the terms of the GNU General Public License as published by the Free 11 + Software Foundation; either version 2, or (at your option) any later 12 + version. 13 + 14 + groff is distributed in the hope that it will be useful, but WITHOUT ANY 15 + WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 + for more details. 18 + 19 + You should have received a copy of the GNU General Public License along 20 + with groff; see the file COPYING. If not, write to the Free Software 21 + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 22 + 23 + #define INT_DIGITS 19 /* enough for 64 bit integer */ 24 + 25 + char *itoa(char *buf, size_t bufsz, long int i) 26 + { 27 + /* Room for INT_DIGITS digits, - and '\0' */ 28 + static char intbuf[INT_DIGITS + 2]; 29 + char *p = intbuf + INT_DIGITS + 1; /* points to terminating '\0' */ 30 + if (i >= 0) { 31 + do { 32 + *--p = '0' + (i % 10); 33 + i /= 10; 34 + } while (i != 0); 35 + } 36 + else { /* i < 0 */ 37 + do { 38 + *--p = '0' - (i % 10); 39 + i /= 10; 40 + } while (i != 0); 41 + *--p = '-'; 42 + } 43 + strmemccpy(buf, p, bufsz); 44 + return buf; 45 + }
+2
firmware/include/string-extra.h
··· 70 70 strmemdupa(__s, MIN(__n, __len)); }) 71 71 #endif /* strndupa */ 72 72 73 + char *itoa(char *buf, size_t bufsz, long int i); /* Not std */ 74 + 73 75 #endif /* STRING_EXTRA_H */