-
Notifications
You must be signed in to change notification settings - Fork 242
- TypeUtil.IsStructImmutable() added, [JSImmutable] works with readonly/structs and more #516
base: master
Are you sure you want to change the base?
Changes from 1 commit
0128da4
5ee6158
265b527
ca92e85
d85d362
1be20ea
71c2726
c9f35f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8313,6 +8313,45 @@ JSIL.Array.ShallowCopy = function (destination, source) { | |
JSIL.Array.CopyTo(source, destination, 0); | ||
}; | ||
|
||
JSIL.Array.FindIndex = function (array, predicate) { // implements: int System.Array.FindIndex<T>(T[] array, Predicate<T> match) | ||
for (var i = 0, l = array.length; i < l; i++) { | ||
if (predicate(array[i])) | ||
return i; | ||
} | ||
return -1; | ||
}; | ||
|
||
JSIL.Array.Find = function (array, predicate) { // implements: T System.Array.Find<T>(T[] array, Predicate<T> match) | ||
for (var i = 0, l = array.length; i < l; i++) { | ||
if (predicate(array[i])) | ||
return array[i]; | ||
} | ||
return null; // use 'null' and not 'undefined' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be |
||
}; | ||
|
||
JSIL.Array.ForEach = function (array, action) { // implements: void ForEach<T>(T[] array, Action<T> action) | ||
if (JSIL.IsTypedArray(array)) { | ||
for (var i = 0, l = array.length; i < l; i++) { | ||
array[i] = action(array[i]); | ||
} | ||
} | ||
else Array.prototype.forEach.call(array, action); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's actually superior to always use the for loop. In many cases a 'self-hosted' JS loop is superior in performance to a native, so forEach is unlikely to be better here. The branch also makes the method harder for a JIT to optimize. |
||
}; | ||
|
||
JSIL.Array.ConvertAll = function (array, converter) { // implements: TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput, TOutput> converter) | ||
var cloned; | ||
if (JSIL.IsTypedArray(array)) { | ||
var ctor = Object.getPrototypeOf(array).constructor; // clone the typed array | ||
cloned = new ctor(array); | ||
for (var i = 0, l = cloned.length; i < l; i++) { | ||
cloned[i] = converter(cloned[i]); | ||
} | ||
} | ||
else cloned = Array.prototype.map.call(array, converter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Let's always use the loop here. Also, I think you want to construct the result array using a length explicitly, then fill it with converted values. (It looks like you pass 'array' to the constructor instead) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix them all and recommit, make all self-hosted loops. |
||
|
||
return cloned; | ||
}; | ||
|
||
$jsilcore.CheckDelegateType = function (value) { | ||
if (value === null) | ||
return false; | ||
|
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.
The recently introduced
MethodSignature.Return(T)
is appropriate for signatures like this when writing new code.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.
How should I use it?
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.
MethodSignature.Return(T)
===new JSIL.MethodSignature(T, [], [])
, but the instance is cached so memory usage is lower and invocation thunks are shared