Revert recycle struct optimisation to avoid pointer overwrites
This commit is contained in:
		
							parent
							
								
									a58159e00e
								
							
						
					
					
						commit
						bb86abb588
					
				
							
								
								
									
										6
									
								
								scan.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								scan.go
									
									
									
									
									
								
							@ -65,7 +65,6 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
 | 
			
		||||
 | 
			
		||||
	db.RowsAffected++
 | 
			
		||||
	db.AddError(rows.Scan(values...))
 | 
			
		||||
 | 
			
		||||
	joinedSchemaMap := make(map[*schema.Field]interface{})
 | 
			
		||||
	for idx, field := range fields {
 | 
			
		||||
		if field == nil {
 | 
			
		||||
@ -242,7 +241,6 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
 | 
			
		||||
		case reflect.Slice, reflect.Array:
 | 
			
		||||
			var (
 | 
			
		||||
				elem        reflect.Value
 | 
			
		||||
				recyclableStruct = reflect.New(reflectValueType)
 | 
			
		||||
				isArrayKind = reflectValue.Kind() == reflect.Array
 | 
			
		||||
			)
 | 
			
		||||
 | 
			
		||||
@ -275,11 +273,7 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					if isPtr && db.RowsAffected > 0 {
 | 
			
		||||
					elem = reflect.New(reflectValueType)
 | 
			
		||||
					} else {
 | 
			
		||||
						elem = recyclableStruct
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				db.scanIntoStruct(rows, elem, values, fields, joinFields)
 | 
			
		||||
 | 
			
		||||
@ -89,9 +89,9 @@ func TestEmbeddedStruct(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
	expectAuthors := []string{"Edward", "George"}
 | 
			
		||||
	for i, post := range egPosts {
 | 
			
		||||
		t.Log(i, post)
 | 
			
		||||
		t.Log(i, post.Author)
 | 
			
		||||
		if want := expectAuthors[i]; post.Author.Name != want {
 | 
			
		||||
			t.Errorf("expected author %s got %s", post.Author.Name, want)
 | 
			
		||||
			t.Errorf("expected author %s got %s", want, post.Author.Name)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user