Changeset 1928 in kBuild
- Timestamp:
- Oct 24, 2008 5:19:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/expand.c
r1927 r1928 51 51 #endif 52 52 char *variable_buffer; 53 54 55 #ifdef CONFIG_WITH_VALUE_LENGTH 56 struct recycled_buffer 57 { 58 struct recycled_buffer *next; 59 unsigned int length; 60 }; 61 struct recycled_buffer *recycled_head; 62 static char * 63 allocated_variable_expand_3 (const char *line, unsigned int length, 64 unsigned int *value_lenp, 65 unsigned int *buffer_lengthp); 66 static void 67 recycle_variable_buffer (char *buffer, unsigned int length); 68 69 #endif 70 71 53 72 54 73 #ifndef KMK … … 87 106 /* If we don't have a variable output buffer yet, get one. */ 88 107 108 #ifdef CONFIG_WITH_VALUE_LENGTH 89 109 if (variable_buffer == 0) 90 110 { 91 #ifdef KMK 92 variable_buffer_length = 384; 111 struct recycled_buffer *recycled = recycled_head; 112 if (recycled) 113 { 114 recycled_head = recycled->next; 115 variable_buffer_length = recycled->length; 116 variable_buffer = (char *)recycled; 117 } 118 else 119 { 120 variable_buffer_length = 384; 121 variable_buffer = xmalloc (variable_buffer_length); 122 } 123 variable_buffer[0] = '\0'; 124 } 93 125 #else 126 if (variable_buffer == 0) 127 { 94 128 variable_buffer_length = 200; 95 #endif96 129 variable_buffer = xmalloc (variable_buffer_length); 97 130 variable_buffer[0] = '\0'; 98 131 } 132 #endif 99 133 100 134 return variable_buffer; … … 545 579 char *op; 546 580 char *abeg = NULL; 581 unsigned int alen = 0; 547 582 const char *end, *colon; 548 583 … … 590 625 /* Expand the name. */ 591 626 saved = *p; 592 *(char *)p = '\0'; /* XXX: proove that this is safe! */593 abeg = allocated_variable_expand_ 2 (beg, p - beg, &len);627 *(char *)p = '\0'; /* XXX: proove that this is safe! XXX2: shouldn't be necessary any longer! */ 628 abeg = allocated_variable_expand_3 (beg, p - beg, &len, &alen); 594 629 beg = abeg; 595 630 end = beg + len; … … 687 722 688 723 if (abeg) 689 free (abeg);724 recycle_variable_buffer (abeg, alen); 690 725 } 691 726 break; … … 1035 1070 return value; 1036 1071 } 1072 1073 /* Handles a special case for variable_expand_string2 where the variable 1074 name is expanded. This variant allows the variable_buffer to 1075 be recycled and thus avoid bothering with a slow free implementation 1076 (darwin is horrible here). */ 1077 1078 static char * 1079 allocated_variable_expand_3 (const char *line, unsigned int length, 1080 unsigned int *value_lenp, 1081 unsigned int *buffer_lengthp) 1082 { 1083 char *obuf = variable_buffer; 1084 unsigned int olen = variable_buffer_length; 1085 long len = (long)length; 1086 char *value; 1087 char *eol; 1088 1089 variable_buffer = 0; 1090 1091 value = variable_expand_string_2 (NULL, line, len, &eol); 1092 *value_lenp = eol - value; 1093 *buffer_lengthp = variable_buffer_length; 1094 1095 variable_buffer = obuf; 1096 variable_buffer_length = olen; 1097 1098 return value; 1099 } 1100 1101 /* recycle a buffer. */ 1102 static void 1103 recycle_variable_buffer (char *buffer, unsigned int length) 1104 { 1105 struct recycled_buffer *recycled = (struct recycled_buffer *)buffer; 1106 1107 assert (!(length & 31)); 1108 assert (length >= 384); 1109 recycled->length = length; 1110 recycled->next = recycled_head; 1111 recycled_head = recycled; 1112 } 1113 1037 1114 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1038 1115
Note:
See TracChangeset
for help on using the changeset viewer.