Skip to content

Commit

Permalink
playlist_viewer reduce bss usage
Browse files Browse the repository at this point in the history
the extra title pointer and alignment adds around 1k to the bss area
since we already have a pointer to track->name we can just save an offset
for the title data

Change-Id: I3a19857631d70276134bcc97940824a3e2f80e4a
  • Loading branch information
Bilgus committed Jul 12, 2024
1 parent 8801ed0 commit da8d615
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions apps/playlist_viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
/* Information about a specific track */
struct playlist_entry {
char *name; /* track path */
char *title; /* Formatted track name */
int index; /* Playlist index */
int display_index; /* Display index */
int attr; /* Is track queued?; Is track marked as bad?*/
int index; /* Playlist index */
int display_index; /* Display index */
uint16_t title_offset; /* where in the buffer the title is located */
uint16_t attr; /* Is track queued?; Is track marked as bad?*/
};

enum direction
Expand Down Expand Up @@ -125,8 +125,6 @@ struct playlist_viewer {
struct playlist_buffer buffer;
};



static struct playlist_viewer viewer;

/* Used when viewing playlists on disk */
Expand Down Expand Up @@ -280,7 +278,7 @@ static int playlist_entry_load(struct playlist_entry *entry, int index,
if (len <= remaining_size)
{
entry->name = name_buffer;
entry->title = name_buffer;
entry->title_offset = 0; /* offset 0 is the first char of name */
entry->index = info.index;
entry->display_index = info.display_index;
entry->attr = info.attr & (PLAYLIST_ATTR_SKIPPED | PLAYLIST_ATTR_QUEUED);
Expand All @@ -295,7 +293,8 @@ static int playlist_entry_load(struct playlist_entry *entry, int index,
return -1; /*Failure */
if (tlen > 0)
{
entry->title = name_buffer;
entry->title_offset = len;
/* offset is the first char after terminating zero of name */
len += tlen;
}
}
Expand Down Expand Up @@ -528,7 +527,7 @@ static void format_line(const struct playlist_entry* track, char* str,
{
char name[MAX_PATH];
char *skipped = "";
format_name(name, track->title, sizeof(name));
format_name(name, track->name + track->title_offset, sizeof(name));

if (track->attr & PLAYLIST_ATTR_SKIPPED)
skipped = "(ERR) ";
Expand Down Expand Up @@ -859,7 +858,7 @@ static int playlist_callback_voice(int selected_item, void *data)
talk_fullpath(track->name, true);
break;
case 2: /*title*/
talk_spell(track->title, true);
talk_spell(track->name + track->title_offset, true);
break;
default:
case 0: /*filename only*/
Expand Down Expand Up @@ -1209,25 +1208,28 @@ static void close_playlist_viewer(void)
}
}

static const char* playlist_search_callback_name(int selected_item, void * data,
char *buffer, size_t buffer_len)
static struct playlist_track_info* get_static_track_info(int *found_indicies, int selected_item)
{
int *found_indicies = (int*)data;
/* playlist_track_info is a large struct keep a static copy to hand out */
static struct playlist_track_info track;
playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
return &track;
}

format_name(buffer, track.filename, buffer_len);
static const char* playlist_search_callback_name(int selected_item, void * data,
char *buffer, size_t buffer_len)
{
struct playlist_track_info *track = get_static_track_info(data, selected_item);
format_name(buffer, track->filename, buffer_len);
return buffer;
}

static int say_search_item(int selected_item, void *data)
{
int *found_indicies = (int*)data;
static struct playlist_track_info track;
playlist_get_track_info(viewer.playlist,found_indicies[selected_item],&track);
struct playlist_track_info *track = get_static_track_info(data, selected_item);
if(global_settings.playlist_viewer_track_display == 1)
talk_fullpath(track.filename, false);
else talk_file_or_spell(NULL, track.filename, NULL, false);
talk_fullpath(track->filename, false);
else talk_file_or_spell(NULL, track->filename, NULL, false);
return 0;
}

Expand Down

0 comments on commit da8d615

Please sign in to comment.