Comment

Comment by amm

Back-of-the-envelope approach that should eliminate most branching:

  int table[256] = {0};                                                           
                                                                                
  void init() {                                                                   
    table['s'] = 1;                                                             
    table['p'] = -1;                                                            
  }                                                                               
                                                                                
  int run_switches(char *input, int size) {                                                 
    int res = 0;                                                                
    while (size-- >= 0) res += table[input[size]];
    return res;                                                                 
  }
parent amm 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton