diff mbox series

[FFmpeg-devel] avformat/rtsp: Put strings instead of pointers to strings into array

Message ID 20200420014204.22606-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 4e254ec6be86977d9ea173f1769398f153bd1d28
Headers show
Series [FFmpeg-devel] avformat/rtsp: Put strings instead of pointers to strings into array | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 20, 2020, 1:42 a.m. UTC
In this example, the difference in length between the shortest and
longest string is three, so that not using pointers to strings saves
space even on 32bit systems.

Moreover, there is no need to use a sentinel here; it can be replaced
with FF_ARRAY_ELEMS.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
I have to admit that this is untested.

 libavformat/rtsp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Ross Nicholson April 20, 2020, 10:25 a.m. UTC | #1
> On 20 Apr 2020, at 02:42, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> 
> In this example, the difference in length between the shortest and
> longest string is three, so that not using pointers to strings saves
> space even on 32bit systems.
> 
> Moreover, there is no need to use a sentinel here; it can be replaced
> with FF_ARRAY_ELEMS.

Thanks, again.

> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> I have to admit that this is untested.
> 
> libavformat/rtsp.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index 0a6462000d..b2b3f32011 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c
> @@ -2526,10 +2526,11 @@ static int rtp_read_header(AVFormatContext *s)
> 
>     p = strchr(s->url, '?');
>     if (p) {
> -        static const char *filters[][2] = {{"sources", "incl"}, {"block", "excl"}, {NULL, NULL}};
> +        static const char filters[][2][8] = { { "sources", "incl" },
> +                                              { "block",   "excl" } };
>         int i;
>         char *q;
> -        for (i = 0; filters[i][0]; i++) {
> +        for (i = 0; i < FF_ARRAY_ELEMS(filters); i++) {
>             if (av_find_info_tag(filters_buf, sizeof(filters_buf), filters[i][0], p)) {
>                 q = filters_buf;
>                 while ((q = strchr(q, ',')) != NULL)
> -- 
> 2.20.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Andreas Rheinhardt April 20, 2020, 4:27 p.m. UTC | #2
Marton Balint:
> 
> 
> On Mon, 20 Apr 2020, Andreas Rheinhardt wrote:
> 
>> In this example, the difference in length between the shortest and
>> longest string is three, so that not using pointers to strings saves
>> space even on 32bit systems.
>>
>> Moreover, there is no need to use a sentinel here; it can be replaced
>> with FF_ARRAY_ELEMS.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>> I have to admit that this is untested.
>>
>> libavformat/rtsp.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
>> index 0a6462000d..b2b3f32011 100644
>> --- a/libavformat/rtsp.c
>> +++ b/libavformat/rtsp.c
>> @@ -2526,10 +2526,11 @@ static int rtp_read_header(AVFormatContext *s)
>>
>>     p = strchr(s->url, '?');
>>     if (p) {
>> -        static const char *filters[][2] = {{"sources", "incl"},
>> {"block", "excl"}, {NULL, NULL}};
>> +        static const char filters[][2][8] = { { "sources", "incl" },
>> +                                              { "block",   "excl" } };
>>         int i;
>>         char *q;
>> -        for (i = 0; filters[i][0]; i++) {
>> +        for (i = 0; i < FF_ARRAY_ELEMS(filters); i++) {
>>             if (av_find_info_tag(filters_buf, sizeof(filters_buf),
>> filters[i][0], p)) {
>>                 q = filters_buf;
>>                 while ((q = strchr(q, ',')) != NULL)
> 
> LGTM, thanks.
> 
> Marton

Applied, thanks.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 0a6462000d..b2b3f32011 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2526,10 +2526,11 @@  static int rtp_read_header(AVFormatContext *s)
 
     p = strchr(s->url, '?');
     if (p) {
-        static const char *filters[][2] = {{"sources", "incl"}, {"block", "excl"}, {NULL, NULL}};
+        static const char filters[][2][8] = { { "sources", "incl" },
+                                              { "block",   "excl" } };
         int i;
         char *q;
-        for (i = 0; filters[i][0]; i++) {
+        for (i = 0; i < FF_ARRAY_ELEMS(filters); i++) {
             if (av_find_info_tag(filters_buf, sizeof(filters_buf), filters[i][0], p)) {
                 q = filters_buf;
                 while ((q = strchr(q, ',')) != NULL)