Removing unnecessary early returns in addTrack, removeTrack and removeRemoteSource...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Nov 2013 01:20:50 +0000 (01:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Nov 2013 01:20:50 +0000 (01:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123644

Patch by Thiago de Barros Lacerda <thiago.lacerda@openbossa.org> on 2013-11-01
Reviewed by Eric Carlson.

No new tests needed.

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::addTrack):
(WebCore::MediaStream::removeTrack):
(WebCore::MediaStream::removeRemoteSource):
(WebCore::MediaStream::trackVectorForType):
* Modules/mediastream/MediaStream.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158470 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h

index 8cd6198..c2fe79b 100644 (file)
@@ -1,3 +1,19 @@
+2013-11-01  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
+
+        Removing unnecessary early returns in addTrack, removeTrack and removeRemoteSource methods
+        https://bugs.webkit.org/show_bug.cgi?id=123644
+
+        Reviewed by Eric Carlson.
+
+        No new tests needed.
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::addTrack):
+        (WebCore::MediaStream::removeTrack):
+        (WebCore::MediaStream::removeRemoteSource):
+        (WebCore::MediaStream::trackVectorForType):
+        * Modules/mediastream/MediaStream.h:
+
 2013-11-01  Andreas Kling  <akling@apple.com>
 
         CSSAspectRatioValue construction helper should return PassRef.
index d7e75b8..42540cf 100644 (file)
@@ -163,10 +163,7 @@ bool MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack)
     if (getTrackById(track->id()))
         return false;
 
-    MediaStreamTrackVector* tracks = getTrackVectorForType(track->source()->type());
-
-    if (!tracks)
-        return false;
+    MediaStreamTrackVector* tracks = trackVectorForType(track->source()->type());
 
     tracks->append(track);
     track->addObserver(this);
@@ -194,10 +191,7 @@ bool MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack)
     // This is a common part used by removeTrack called by JavaScript
     // and removeRemoteTrack and only removeRemoteTrack must fire removetrack event
     RefPtr<MediaStreamTrack> track = prpTrack;
-    MediaStreamTrackVector* tracks = getTrackVectorForType(track->source()->type());
-
-    if (!tracks)
-        return false;
+    MediaStreamTrackVector* tracks = trackVectorForType(track->source()->type());
 
     size_t pos = tracks->find(track);
     if (pos == notFound)
@@ -290,10 +284,7 @@ void MediaStream::removeRemoteSource(MediaStreamSource* source)
     if (ended())
         return;
 
-    Vector<RefPtr<MediaStreamTrack>>* tracks = getTrackVectorForType(source->type());
-
-    if (!tracks)
-        return;
+    Vector<RefPtr<MediaStreamTrack>>* tracks = trackVectorForType(source->type());
 
     for (int i = tracks->size() - 1; i >= 0; --i) {
         if ((*tracks)[i]->source() != source)
@@ -371,21 +362,17 @@ URLRegistry& MediaStream::registry() const
     return MediaStreamRegistry::registry();
 }
 
-MediaStreamTrackVector* MediaStream::getTrackVectorForType(MediaStreamSource::Type type)
+MediaStreamTrackVector* MediaStream::trackVectorForType(MediaStreamSource::Type type)
 {
-    MediaStreamTrackVector* tracks = nullptr;
     switch (type) {
     case MediaStreamSource::Audio:
-        tracks = &m_audioTracks;
-        break;
+        return &m_audioTracks;
     case MediaStreamSource::Video:
-        tracks = &m_videoTracks;
-        break;
+        return &m_videoTracks;
     case MediaStreamSource::None:
         ASSERT_NOT_REACHED();
-        break;
     }
-    return tracks;
+    return nullptr;
 }
 
 } // namespace WebCore
index 8fe19d3..3d674c5 100644 (file)
@@ -110,7 +110,7 @@ private:
 
     void cloneMediaStreamTrackVector(MediaStreamTrackVector&, const MediaStreamTrackVector&);
 
-    MediaStreamTrackVector* getTrackVectorForType(MediaStreamSource::Type);
+    MediaStreamTrackVector* trackVectorForType(MediaStreamSource::Type);
 
     RefPtr<MediaStreamDescriptor> m_descriptor;
     MediaStreamTrackVector m_audioTracks;