Performance tweak: reduce number of function call of strlen()

minor performance tweak, reduce number of call to strlen().