Is there any other way to make this switch-condition without repeating code and not slower in performance?