From 0237439056d31b2ffe93bb36671c00b622ff734c Mon Sep 17 00:00:00 2001 From: Alex Chronopoulos Date: Mon, 16 Jul 2018 11:30:46 +0200 Subject: [PATCH] Bug 1152401 - Use mKind member of MediaDevice in MediaDeviceInfo to avoid string comparisons. r=jib MozReview-Commit-ID: Kfqb7DZlwO2 --HG-- extra : rebase_source : 9e3ec1b4df4d90a20ff270f0e83a789631890cbe --- dom/media/MediaDevices.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index 341ffaa31e4d..53adbe3f21fe 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -113,24 +113,21 @@ public: } nsTArray> infos; for (auto& device : devices) { - MediaDevice* dev = static_cast(device.get()); - bool isVideo = dev->mKind == dom::MediaDeviceKind::Videoinput; - bool isAudio = dev->mKind == dom::MediaDeviceKind::Audioinput; - if (isVideo || isAudio) { - MediaDeviceKind kind = isVideo ? - MediaDeviceKind::Videoinput : MediaDeviceKind::Audioinput; - nsString id; - nsString name; - device->GetId(id); - // Include name only if page currently has a gUM stream active or - // persistent permissions (audio or video) have been granted - if (MediaManager::Get()->IsActivelyCapturingOrHasAPermission(mWindowId) || - Preferences::GetBool("media.navigator.permission.disabled", false)) { - device->GetName(name); - } - RefPtr info = new MediaDeviceInfo(id, kind, name); - infos.AppendElement(info); + MediaDeviceKind kind = static_cast(device.get())->mKind; + MOZ_ASSERT(kind == dom::MediaDeviceKind::Audioinput + || kind == dom::MediaDeviceKind::Videoinput + || kind == dom::MediaDeviceKind::Audiooutput); + nsString id; + nsString name; + device->GetId(id); + // Include name only if page currently has a gUM stream active or + // persistent permissions (audio or video) have been granted + if (MediaManager::Get()->IsActivelyCapturingOrHasAPermission(mWindowId) || + Preferences::GetBool("media.navigator.permission.disabled", false)) { + device->GetName(name); } + RefPtr info = new MediaDeviceInfo(id, kind, name); + infos.AppendElement(info); } mPromise->MaybeResolve(infos); return NS_OK;