mirror of
				https://github.com/roc-lang/roc.git
				synced 2025-11-03 22:13:35 +00:00 
			
		
		
		
	refactor string reallocation
This commit is contained in:
		
							parent
							
								
									ac33fd3237
								
							
						
					
					
						commit
						e551e59c1c
					
				
					 1 changed files with 14 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -157,14 +157,16 @@ pub const RocStr = extern struct {
 | 
			
		|||
        const element_width = 1;
 | 
			
		||||
        const old_capacity = self.getCapacity();
 | 
			
		||||
 | 
			
		||||
        if (self.isSmallStr() or !self.isUnique()) {
 | 
			
		||||
            return self.reallocateFresh(new_length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (self.str_bytes) |source_ptr| {
 | 
			
		||||
            const unique = self.isUnique();
 | 
			
		||||
            if (unique and old_capacity > new_length) {
 | 
			
		||||
            if (old_capacity > new_length) {
 | 
			
		||||
                var output = self;
 | 
			
		||||
                output.setLen(new_length);
 | 
			
		||||
                return output;
 | 
			
		||||
            }
 | 
			
		||||
            if (unique and !self.isSmallStr()) {
 | 
			
		||||
            const new_capacity = utils.calculateCapacity(old_capacity, new_length, element_width);
 | 
			
		||||
            const new_source = utils.unsafeReallocate(
 | 
			
		||||
                source_ptr,
 | 
			
		||||
| 
						 | 
				
			
			@ -176,8 +178,6 @@ pub const RocStr = extern struct {
 | 
			
		|||
 | 
			
		||||
            return RocStr{ .str_bytes = new_source, .str_len = new_length, .str_capacity = new_capacity };
 | 
			
		||||
        }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return self.reallocateFresh(new_length);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue