Reading Infrared raw data
int digitalRead(uint8_t pin)
{
    uint8_t timer = digitalPinToTimer(pin);
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);

    if (port == NOT_A_PIN) return LOW;

    // If the pin that support PWM output, we need to turn it off
    // before getting a digital reading.
    if (timer != NOT_ON_TIMER) turnOffPWM(timer);

    if (*portInputRegister(port) &amp; bit) return HIGH;
    return LOW;
}


1) so it 


calls function digitalRead() (puts value on stack, jumps, prepare function frame - each cost some time)
calls 3 other functions (with all the same problems)
check for sanity of value
check for PWN (and eventually calls another function)
does the PIND &amp; (0b100)
returns from function (so read stack, clear the frame, jumps, set the result)


just to obtain the same functionality 


typical for library functions, that each call makes sure the environment is sane and expected each and every time it is called - in close loop you can check it onece before and then just do not broke it
translates parameter from nice arduino numbers to real addresses and bits each and every time again


2) it access the PORT D (see AVR (the processor) internal construction) and reads value of its 3. bit (which maps to the relevant pin of the chip/Arduino board

3) see following comment - it is expected length of the pulse (maybe with some safety limit)

4) _BV is for BitValue - shift 1 to position given by arg (that is macro doind 1 &lt;&lt; IRpin) maybe more nice/readable version, compiles to the same. (the ! is ofcourse negaition)