Changeset 268555 in webkit


Ignore:
Timestamp:
Oct 15, 2020 2:26:56 PM (3 years ago)
Author:
Chris Dumez
Message:

Use std::fill_n() instead of for loops in AudioParamTimeline
https://bugs.webkit.org/show_bug.cgi?id=217775

Reviewed by Darin Adler.

Use std::fill_n() instead of for loops in AudioParamTimeline.

No new tests, no Web facing behavior change.

  • Modules/webaudio/AudioParamTimeline.cpp:

(WebCore::fillWithValue):
(WebCore::AudioParamTimeline::valuesForFrameRange):
(WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
(WebCore::AudioParamTimeline::processExponentialRamp):
(WebCore::AudioParamTimeline::processCancelValues):
(WebCore::AudioParamTimeline::processSetTarget):
(WebCore::AudioParamTimeline::processSetValueCurve):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268553 r268555  
     12020-10-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Use std::fill_n() instead of for loops in AudioParamTimeline
     4        https://bugs.webkit.org/show_bug.cgi?id=217775
     5
     6        Reviewed by Darin Adler.
     7
     8        Use std::fill_n() instead of for loops in AudioParamTimeline.
     9
     10        No new tests, no Web facing behavior change.
     11
     12        * Modules/webaudio/AudioParamTimeline.cpp:
     13        (WebCore::fillWithValue):
     14        (WebCore::AudioParamTimeline::valuesForFrameRange):
     15        (WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
     16        (WebCore::AudioParamTimeline::processExponentialRamp):
     17        (WebCore::AudioParamTimeline::processCancelValues):
     18        (WebCore::AudioParamTimeline::processSetTarget):
     19        (WebCore::AudioParamTimeline::processSetValueCurve):
     20
    1212020-10-15  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp

    r268414 r268555  
    3838namespace WebCore {
    3939
     40static void fillWithValue(float* values, float value, unsigned endFrame, unsigned& writeIndex)
     41{
     42    if (writeIndex < endFrame) {
     43        std::fill_n(values + writeIndex, endFrame - writeIndex, value);
     44        writeIndex = endFrame;
     45    }
     46}
     47
    4048// Test that for a SetTarget event, the current value is close enough to the target value that
    4149// we can consider the event to have converged to the target.
     
    340348    auto locker = tryHoldLock(m_eventsLock);
    341349    if (!locker) {
    342         if (values) {
    343             for (unsigned i = 0; i < numberOfValues; ++i)
    344                 values[i] = defaultValue;
    345         }
     350        std::fill_n(values, numberOfValues, defaultValue);
    346351        return defaultValue;
    347352    }
     
    365370    // Return default value if there are no events matching the desired time range.
    366371    if (!m_events.size() || endFrame * samplingPeriod <= m_events[0]->time().value()) {
    367         for (unsigned i = 0; i < numberOfValues; ++i)
    368             values[i] = defaultValue;
     372        std::fill_n(values, numberOfValues, defaultValue);
    369373        return defaultValue;
    370374    }
     
    386390        unsigned fillToFrame = static_cast<unsigned>(fillToEndFrame - startFrame);
    387391        fillToFrame = std::min(fillToFrame, numberOfValues);
    388         for (; writeIndex < fillToFrame; ++writeIndex)
    389             values[writeIndex] = defaultValue;
     392        fillWithValue(values, defaultValue, fillToFrame, writeIndex);
    390393
    391394        currentFrame += fillToFrame;
     
    460463                // Simply stay at a constant value.
    461464                value = event->value();
    462                 for (; writeIndex < fillToFrame; ++writeIndex)
    463                     values[writeIndex] = value;
    464 
     465                fillWithValue(values, value, fillToFrame, writeIndex);
    465466                break;
    466467            case ParamEvent::CancelValues:
     
    482483    // If there's any time left after processing the last event then just propagate the last value
    483484    // to the end of the values buffer.
    484     for (; writeIndex < numberOfValues; ++writeIndex)
    485         values[writeIndex] = value;
     485    fillWithValue(values, value, numberOfValues, writeIndex);
    486486
    487487    return value;
     
    546546        // If value1 and value2 have opposite signs or if value1 is zero, then v(t) = value1 for T0 <= t < T1.
    547547        value = currentState.value1;
    548         for (; writeIndex < currentState.fillToFrame; ++writeIndex)
    549             values[writeIndex] = value;
     548        fillWithValue(values, value, currentState.fillToFrame, writeIndex);
    550549        return;
    551550    }
     
    592591    }
    593592
    594     for (; writeIndex < currentState.fillToFrame; ++writeIndex)
    595         values[writeIndex] = value;
     593    fillWithValue(values, value, currentState.fillToFrame, writeIndex);
    596594
    597595    currentFrame = currentState.fillToEndFrame;
     
    627625    if (hasSetTargetConverged(value, target, Seconds { currentFrame * currentState.samplingPeriod }, currentState.time1, timeConstant)) {
    628626        currentFrame += currentState.fillToFrame - writeIndex;
    629         for (; writeIndex < currentState.fillToFrame; ++writeIndex)
    630             values[writeIndex] = target;
     627        fillWithValue(values, target, currentState.fillToFrame, writeIndex);
    631628        value = target;
    632629        return;
     
    691688        // Error condition - simply propagate previous value.
    692689        currentFrame = fillToEndFrame;
    693         for (; writeIndex < fillToFrame; ++writeIndex)
    694             values[writeIndex] = value;
     690        fillWithValue(values, value, fillToFrame, writeIndex);
    695691        return;
    696692    }
     
    759755    if (writeIndex < nextEventFillToFrame) {
    760756        value = curveEndValue;
    761         for (; writeIndex < nextEventFillToFrame; ++writeIndex)
    762             values[writeIndex] = value;
     757        fillWithValue(values, value, nextEventFillToFrame, writeIndex);
    763758    }
    764759
Note: See TracChangeset for help on using the changeset viewer.