Ticket #1493: avoid_duplicate_const_string.patch

File avoid_duplicate_const_string.patch, 1.4 KB (added by NotFound, 12 years ago)
  • compilers/imcc/pbc.c

     
    981981add_const_str(PARROT_INTERP, ARGIN(const SymReg *r)) 
    982982{ 
    983983    ASSERT_ARGS(add_const_str) 
    984     const int      k = add_const_table(interp); 
     984 
     985    PackFile_ConstTable *table = interp->code->const_table; 
    985986    STRING * const s = IMCC_string_from_reg(interp, r); 
    986     PackFile_Constant * const constant = interp->code->const_table->constants[k]; 
    987  
    988     constant->type     = PFC_STRING; 
    989     constant->u.string = s; 
    990  
    991  
     987    int k = -1; 
     988    int i; 
     989    for (i = 0; i < table->const_count; ++i) { 
     990        PackFile_Constant * const constant = table->constants[i]; 
     991        if (constant->type == PFC_STRING) { 
     992            STRING * const sc = constant->u.string; 
     993            if (Parrot_charset_number_of_str(interp, s) == 
     994                    Parrot_charset_number_of_str(interp, sc) && 
     995                    Parrot_encoding_number_of_str(interp, s) == 
     996                    Parrot_encoding_number_of_str(interp, sc) && 
     997                    Parrot_str_equal(interp, s, sc)) { 
     998                k = i; 
     999                break; 
     1000            } 
     1001        } 
     1002    } 
     1003    if (k < 0) { 
     1004        PackFile_Constant * constant; 
     1005        k = add_const_table(interp); 
     1006        constant = table->constants[k]; 
     1007        constant->type     = PFC_STRING; 
     1008        constant->u.string = s; 
     1009    } 
    9921010    return k; 
    9931011} 
    9941012