Prevent unneeded memory allocation in Strgrow
This commit is contained in:
		
							
								
								
									
										14
									
								
								Str.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								Str.c
									
									
									
									
									
								
							| @@ -288,13 +288,15 @@ Strgrow(Str x) | |||||||
| 	if (x->length + 1 >= newlen) | 	if (x->length + 1 >= newlen) | ||||||
| 	    x->length = newlen - 2; | 	    x->length = newlen - 2; | ||||||
|     } |     } | ||||||
|     x->ptr = GC_MALLOC_ATOMIC(newlen); |     if (x->area_size < newlen) { | ||||||
|     if (x->ptr == NULL) | 	x->ptr = GC_MALLOC_ATOMIC(newlen); | ||||||
| 	exit(1); | 	if (x->ptr == NULL) | ||||||
|     x->area_size = newlen; | 	    exit(1); | ||||||
|     bcopy((void *)old, (void *)x->ptr, x->length); | 	x->area_size = newlen; | ||||||
|  | 	bcopy((void *)old, (void *)x->ptr, x->length); | ||||||
|  | 	GC_free(old); | ||||||
|  |     } | ||||||
|     x->ptr[x->length] = '\0'; |     x->ptr[x->length] = '\0'; | ||||||
|     GC_free(old); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| Str | Str | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user