Ticket #1781: mc-4.7.0-pre4-slowStart.patch

File mc-4.7.0-pre4-slowStart.patch, 5.0 KB (added by 0xe2.0x9a.0x9b, 12 years ago)
  • src/keybind.c

    diff -Naur mc-4.7.0-pre4/src/keybind.c mc-4.7.0-pre4-patched/src/keybind.c
    old new  
    4545 
    4646#include "keybind.h" 
    4747 
    48 static const name_keymap_t command_names[] = { 
     48static name_keymap_t command_names[] = { 
    4949#ifdef USE_INTERNAL_EDIT 
    5050    { "EditNoCommand",                     CK_Ignore_Key }, 
    5151    { "EditIgnoreKey",                     CK_Ignore_Key }, 
     
    401401    { NULL,                              0 } 
    402402}; 
    403403 
     404static const int num_command_names = sizeof(command_names)/sizeof(command_names[0]) - 1; 
     405 
    404406/*** global variables ****************************************************************************/ 
    405407 
    406408/* viewer/actions_cmd.c */ 
     
    770772}; 
    771773 
    772774 
     775 
     776static int name_keymap_comparator(const void *p1, const void *p2) 
     777{ 
     778    const name_keymap_t *m1 = (const name_keymap_t*)p1; 
     779    const name_keymap_t *m2 = (const name_keymap_t*)p2; 
     780 
     781    return str_casecmp(m1->name, m2->name); 
     782} 
     783 
     784static void sort_command_names() 
     785{ 
     786    static int has_been_sorted = 0; 
     787 
     788    if(!has_been_sorted) { 
     789        qsort(command_names, num_command_names, sizeof(command_names[0]), &name_keymap_comparator); 
     790        has_been_sorted = 1; 
     791    } 
     792} 
     793 
    773794int 
    774795lookup_action (const char *keyname) 
    775796{ 
    776     int i; 
     797    const name_keymap_t key = {keyname, /*insignificant*/0}; 
     798    name_keymap_t *res; 
    777799 
    778     for (i = 0; command_names [i].name; i++) 
    779         if (!str_casecmp (command_names [i].name, keyname)) 
    780             return command_names [i].val; 
     800    sort_command_names(); 
     801    res = bsearch(&key, command_names, num_command_names, sizeof(command_names[0]), name_keymap_comparator); 
    781802 
    782     return 0; 
     803    return (res != NULL) ? res->val : 0; 
    783804} 
    784805 
    785806static void 
  • src/tty/key.c

    diff -Naur mc-4.7.0-pre4/src/tty/key.c mc-4.7.0-pre4-patched/src/tty/key.c
    old new  
    9393 * We use this to allow users to define alternate definitions for 
    9494 * certain keys that may be missing from the terminal database 
    9595 */ 
    96 key_code_name_t key_name_conv_tab[] = { 
     96const key_code_name_t key_name_conv_tab[] = { 
    9797    /* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason 
    9898        to define f0 as well. Also, it makes Learn keys a bunch of problems :( */ 
    9999    { KEY_F (1),        "f1",           N_("Function key 1"),   "F1" }, 
     
    12291229    return MSG_HANDLED; 
    12301230} 
    12311231 
     1232 
     1233static const int key_name_conv_tab__size = sizeof(key_name_conv_tab) / sizeof(key_name_conv_tab[0]) - 1; 
     1234 
     1235static key_code_name_t key_name_conv_tab__sorted[ sizeof(key_name_conv_tab) / sizeof(key_name_conv_tab[0]) - 1 ]; 
     1236 
     1237static int key_code_name_comparator(const void *p1, const void *p2) 
     1238{ 
     1239    const key_code_name_t *n1 = (const key_code_name_t*)p1; 
     1240    const key_code_name_t *n2 = (const key_code_name_t*)p2; 
     1241 
     1242    return str_casecmp(n1->name, n2->name); 
     1243} 
     1244 
     1245static void sort_key_name_conv_tab() 
     1246{ 
     1247    static int has_been_sorted = 0; 
     1248 
     1249    if(!has_been_sorted) { 
     1250        int i; 
     1251        for (i = 0; key_name_conv_tab[i].code; i++) 
     1252            key_name_conv_tab__sorted[i] = key_name_conv_tab[i]; 
     1253 
     1254        qsort(key_name_conv_tab__sorted, key_name_conv_tab__size, 
     1255              sizeof(key_name_conv_tab__sorted[0]), &key_code_name_comparator); 
     1256 
     1257        has_been_sorted = 1; 
     1258    } 
     1259} 
     1260 
    12321261static int 
    12331262lookup_keyname (const char *keyname, int *lc_index) 
    12341263{ 
    12351264    if (keyname[0] != '\0') { 
    1236         int i; 
     1265//      int i; 
    12371266 
    12381267        if (keyname[1] == '\0') { 
    12391268            *lc_index = -1; 
    12401269            return (int) keyname[0]; 
    12411270        } 
     1271        else { 
     1272            const key_code_name_t key = { 
     1273                .name = keyname 
     1274            }; 
     1275            key_code_name_t *res; 
     1276 
     1277            sort_key_name_conv_tab(); 
     1278            res = bsearch(&key, 
     1279                          key_name_conv_tab__sorted, 
     1280                          key_name_conv_tab__size, sizeof(key_name_conv_tab__sorted[0]), 
     1281                          key_code_name_comparator); 
     1282 
     1283            if(res != NULL) { 
     1284                *lc_index = (res - key_name_conv_tab__sorted); 
     1285                return res->code; 
     1286            } 
     1287        } 
    12421288 
    1243         for (i = 0; key_name_conv_tab[i].code; i++) 
     1289/*      for (i = 0; key_name_conv_tab[i].code; i++) 
    12441290            if (str_casecmp (key_name_conv_tab[i].name, keyname) == 0) { 
    12451291                *lc_index = i; 
    12461292                return key_name_conv_tab[i].code; 
    1247             } 
     1293            }*/ 
    12481294    } 
    12491295 
    12501296    *lc_index = -1; 
  • src/tty/key.h

    diff -Naur mc-4.7.0-pre4/src/tty/key.h mc-4.7.0-pre4-patched/src/tty/key.h
    old new  
    2323                              move_fn backfn, move_fn forfn, move_fn topfn, move_fn bottomfn); 
    2424int lookup_key (const char *keyname, char **label); 
    2525 
    26 typedef const struct { 
     26typedef struct { 
    2727    int code; 
    2828    const char *name; 
    2929    const char *longname; 
    3030    const char *shortcut; 
    3131} key_code_name_t; 
    3232 
    33 extern key_code_name_t key_name_conv_tab[]; 
     33extern const key_code_name_t key_name_conv_tab[]; 
    3434 
    3535/* mouse support */ 
    3636struct Gpm_Event;