Changeset 6668

Show
Ignore:
Timestamp:
01/02/11 19:16:54 (2 years ago)
Author:
jow
Message:

libs/lmo: skip all entries with identical key and value when generating lmo archives

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/lmo/src/lmo_po2lmo.c

    r5487 r6668  
    22 * lmo - Lua Machine Objects - PO to LMO conversion tool 
    33 * 
    4  *   Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> 
     4 *   Copyright (C) 2009-2011 Jo-Philipp Wich <xm@subsignal.org> 
    55 * 
    66 *  Licensed under the Apache License, Version 2.0 (the "License"); 
     
    6060                off++; 
    6161                esc = 1; 
    62                  
    6362            } 
    6463            else if( src[pos] != '"' ) 
     
    8685    int offset = 0; 
    8786    int length = 0; 
     87    uint32_t key_id, val_id; 
    8888 
    8989    FILE *in; 
     
    156156            if( strlen(key) > 0 && strlen(val) > 0 ) 
    157157            { 
    158                 if( (entry = (lmo_entry_t *) malloc(sizeof(lmo_entry_t))) != NULL ) 
     158                key_id = sfh_hash(key, strlen(key)); 
     159                val_id = sfh_hash(val, strlen(val)); 
     160 
     161                if( key_id != val_id ) 
    159162                { 
    160                     memset(entry, 0, sizeof(entry)); 
    161                     length = strlen(val) + ((4 - (strlen(val) % 4)) % 4); 
    162  
    163                     entry->key_id = htonl(sfh_hash(key, strlen(key))); 
    164                     entry->val_id = htonl(sfh_hash(val, strlen(val))); 
    165                     entry->offset = htonl(offset); 
    166                     entry->length = htonl(strlen(val)); 
    167  
    168                     print(val, length, 1, out); 
    169                     offset += length; 
    170  
    171                     entry->next = head; 
    172                     head = entry; 
    173                 } 
    174                 else 
    175                 { 
    176                     die("Out of memory"); 
     163                    if( (entry = (lmo_entry_t *) malloc(sizeof(lmo_entry_t))) != NULL ) 
     164                    { 
     165                        memset(entry, 0, sizeof(entry)); 
     166                        length = strlen(val) + ((4 - (strlen(val) % 4)) % 4); 
     167 
     168                        entry->key_id = htonl(key_id); 
     169                        entry->val_id = htonl(val_id); 
     170                        entry->offset = htonl(offset); 
     171                        entry->length = htonl(strlen(val)); 
     172 
     173                        print(val, length, 1, out); 
     174                        offset += length; 
     175 
     176                        entry->next = head; 
     177                        head = entry; 
     178                    } 
     179                    else 
     180                    { 
     181                        die("Out of memory"); 
     182                    } 
    177183                } 
    178184            }