I’ve taken code I’ve written for a previous employer and used it on my current task simply to save time.

Almost certainly, this is not allowed. You were paid by the previous employer to generate code (and value) for them, not for your second employer.

That said, it's often difficult to avoid reinventing the wheel in exactly the same way that you reinvented it the previous time, but as long as you don't dip into work that you did for a previous employer, that's fine, IMO.

Of course, IANAL.

If you're consulting/contracting, then the reuse of source code that you create is governed by that contract.

In the past, the company that I was working for full time wrote some code for someone. They wanted an exclusive license to that code, so once we'd handed it over, we had to delete all of our copies, and were not allowed to use it in any further work. Pity -- there was some cool stuff in there that I don't particularly fancy rewriting from scratch. Thems the breaks, though.
_________________________
-- roger