[FFmpeg-devel] [PATCH 2.2/3] libavformat/protocols.c: avio_enum_protocols(): Convert recursion to iteration
Michael Witten
mfwitten at gmail.com
Wed Aug 11 22:00:04 EEST 2021
In C, it's generally not good to write a recursive algorithm,
because it is not possible to rely on the compiler to elide
a tail call; therefore, this commit converts a tail call into
an iterative loop by means of an explicit 'goto' statement.
---
libavformat/protocols.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 1c5e3b2bdb..b0aae66dab 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -95,6 +95,7 @@ const char *avio_enum_protocols(void **const opaque, const int output)
{
const URLProtocol *const *p;
+iterate:
p = *opaque;
p = p ? p + 1 : url_protocols;
*opaque = (void *)p;
@@ -104,7 +105,7 @@ const char *avio_enum_protocols(void **const opaque, const int output)
}
if ((output && (*p)->url_write) || (!output && (*p)->url_read))
return (*p)->name;
- return avio_enum_protocols(opaque, output);
+ goto iterate;
}
const AVClass *avio_protocol_get_class(const char *name)
--
2.22.0
More information about the ffmpeg-devel
mailing list