-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring/externalized html #234
Conversation
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
========================================
- Coverage 59.2% 58.9% -0.3%
========================================
Files 181 179 -2
Lines 5234 5262 +28
========================================
- Hits 3098 3097 -1
- Misses 1791 1820 +29
Partials 345 345 |
pkg/runtime/values/helpers.go
Outdated
|
||
switch result.Type() { | ||
case types.Object: | ||
if resultType == types.Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe switch-case
would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe :)
pkg/runtime/values/helpers.go
Outdated
case types.Array: | ||
return input.Copy(), nil | ||
case types.Object: | ||
obj, ok := input.(*Object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if input.Type()
returns types.Object
, can we get ok == false
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, we can switch input.(type)
, not input.Type()
It will looks like:
switch value := input.(type) {
case Boolean,
Int,
Float,
String,
DateTime:
return NewArrayWith(value), nil
case *Array:
return value.Copy(), nil
case *Object:
arr := NewArray(int(value.Length()))
value.ForEach(func(value core.Value, key string) bool {
arr.Push(value)
return true
})
return value, nil
case core.Iterable:
iterator, err := value.Iterate(ctx)
if err != nil {
return None, err
}
arr := NewArray(10)
for {
val, _, err := iterator.Next(ctx)
if err != nil {
return None, err
}
if val == None {
break
}
arr.Push(val)
}
return arr, nil
default:
return NewArray(0), nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point. But if a value has type of type.Object
but isn't values.Object
it means that someone messed up with types.
The reason why I created Type
interface is that I wanted to avoid type assertion as much as I could because of its possible (in some cases) negative impact on performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But ideally, we need to write benchmarks to see the impact. It seems in recent version of Go, it has been improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will be main performance problem, but OK :)
pkg/runtime/values/helpers.go
Outdated
obj, ok := attrs.(*Object) | ||
return NewArrayWith(input), nil | ||
case types.Array: | ||
return input.Copy(), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to #8 (comment), we should return only new instances. Think we should use Clone
instead of Copy
.
It can shoot here:
ferret/pkg/stdlib/types/to_array.go
Lines 16 to 24 in ba8f373
func ToArray(ctx context.Context, args ...core.Value) (core.Value, error) { | |
err := core.ValidateArgs(args, 1, 1) | |
if err != nil { | |
return values.None, err | |
} | |
return values.ToArray(ctx, args[0]) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I do not think it's valid here. We create a new array with the same content. I think it's an intended behavior, isn't it?
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
No description provided.