The encoder library for Arduino is pretty good for this. It will use interrupts, so if you put input A onto a pin that has a pin-change interrupt (only pin 2 and 3 on the Uno, others have more interrupt pins) then the library will use that and your code doesn't need to keep polling input A.