gst/gstbuffer.c: Avoid function call for known types by keeping the buffer and subbuf...
authorWim Taymans <wim.taymans@gmail.com>
Wed, 26 Jul 2006 10:39:58 +0000 (10:39 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Wed, 26 Jul 2006 10:39:58 +0000 (10:39 +0000)
Original commit message from CVS:
* gst/gstbuffer.c: (gst_buffer_get_type), (gst_buffer_new),
(gst_subbuffer_get_type), (gst_buffer_create_sub):
Avoid function call for known types by keeping the buffer and
subbuffer GType global.
* plugins/elements/gstfilesrc.c: (gst_file_src_create_read):
Random silly optimisations in read() path.

ChangeLog
gst/gstbuffer.c
plugins/elements/gstfilesrc.c

index 1f5b707..a8bfd92 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-07-26  Wim Taymans  <wim@fluendo.com>
+
+       * gst/gstbuffer.c: (gst_buffer_get_type), (gst_buffer_new),
+       (gst_subbuffer_get_type), (gst_buffer_create_sub):
+       Avoid function call for known types by keeping the buffer and
+       subbuffer GType global.
+
+       * plugins/elements/gstfilesrc.c: (gst_file_src_create_read):
+       Random silly optimisations in read() path.
+
 2006-07-26  Jan Schmidt  <thaytan@mad.scientist.com>
 
        * tools/gst-launch.c: (main):
index 5bfe673..39a0e89 100644 (file)
 #include "gstutils.h"
 #include "gstminiobject.h"
 
-
 static void gst_buffer_init (GTypeInstance * instance, gpointer g_class);
 static void gst_buffer_class_init (gpointer g_class, gpointer class_data);
 static void gst_buffer_finalize (GstBuffer * buffer);
 static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
 static GType gst_subbuffer_get_type (void);
 
+static GType _gst_subbuffer_type = 0;
+static GType _gst_buffer_type = 0;
+
 void
 _gst_buffer_initialize (void)
 {
@@ -141,8 +143,6 @@ _gst_buffer_initialize (void)
 GType
 gst_buffer_get_type (void)
 {
-  static GType _gst_buffer_type = 0;
-
   if (G_UNLIKELY (_gst_buffer_type == 0)) {
     static const GTypeInfo buffer_info = {
       sizeof (GstBufferClass),
@@ -256,7 +256,7 @@ gst_buffer_new (void)
 {
   GstBuffer *newbuf;
 
-  newbuf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER);
+  newbuf = (GstBuffer *) gst_mini_object_new (_gst_buffer_type);
 
   GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
 
@@ -388,10 +388,7 @@ gst_buffer_make_metadata_writable (GstBuffer * buf)
 typedef struct _GstSubBuffer GstSubBuffer;
 typedef struct _GstSubBufferClass GstSubBufferClass;
 
-#define GST_TYPE_SUBBUFFER                         (gst_subbuffer_get_type())
-
-#define GST_IS_SUBBUFFER(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SUBBUFFER))
-#define GST_SUBBUFFER(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SUBBUFFER, GstSubBuffer))
+#define GST_IS_SUBBUFFER(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), _gst_subbuffer_type))
 #define GST_SUBBUFFER_CAST(obj) ((GstSubBuffer *)(obj))
 
 struct _GstSubBuffer
@@ -415,8 +412,6 @@ static void gst_subbuffer_finalize (GstSubBuffer * buffer);
 static GType
 gst_subbuffer_get_type (void)
 {
-  static GType _gst_subbuffer_type = 0;
-
   if (G_UNLIKELY (_gst_subbuffer_type == 0)) {
     static const GTypeInfo subbuffer_info = {
       sizeof (GstSubBufferClass),
@@ -499,7 +494,7 @@ gst_buffer_create_sub (GstBuffer * buffer, guint offset, guint size)
   gst_buffer_ref (parent);
 
   /* create the new buffer */
-  subbuffer = (GstSubBuffer *) gst_mini_object_new (GST_TYPE_SUBBUFFER);
+  subbuffer = (GstSubBuffer *) gst_mini_object_new (_gst_subbuffer_type);
   subbuffer->parent = parent;
 
   GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p (parent %p)", subbuffer,
index 8db8237..3ea7afd 100644 (file)
@@ -751,11 +751,11 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length,
   int ret;
   GstBuffer *buf;
 
-  if (src->read_position != offset) {
+  if (G_UNLIKELY (src->read_position != offset)) {
     off_t res;
 
     res = lseek (src->fd, offset, SEEK_SET);
-    if (res < 0 || res != offset)
+    if (G_UNLIKELY (res < 0 || res != offset))
       goto seek_failed;
 
     src->read_position = offset;
@@ -765,19 +765,17 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length,
 
   GST_LOG_OBJECT (src, "Reading %d bytes", length);
   ret = read (src->fd, GST_BUFFER_DATA (buf), length);
-  if (ret < 0)
+  if (G_UNLIKELY (ret < 0))
     goto could_not_read;
 
   /* regular files should have given us what we expected */
-  if ((guint) ret < length && src->is_regular)
+  if (G_UNLIKELY ((guint) ret < length && src->is_regular))
     goto unexpected_eos;
 
   /* other files should eos if they read 0 */
-  if (ret == 0) {
-    GST_DEBUG ("non-regular file hits EOS");
-    gst_buffer_unref (buf);
-    return GST_FLOW_UNEXPECTED;
-  }
+  if (G_UNLIKELY (ret == 0))
+    goto eos;
+
   length = ret;
 
   GST_BUFFER_SIZE (buf) = length;
@@ -809,6 +807,12 @@ unexpected_eos:
     gst_buffer_unref (buf);
     return GST_FLOW_ERROR;
   }
+eos:
+  {
+    GST_DEBUG ("non-regular file hits EOS");
+    gst_buffer_unref (buf);
+    return GST_FLOW_UNEXPECTED;
+  }
 }
 
 static GstFlowReturn