updated encode.c with more optimisation

check if char is ASCII first before other conditions.
code to handle empty document. (buf_len == 0)