Skip to content

Commit

Permalink
Merge pull request #1055 from fabulous-dev/remove-dot-before-index
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere authored Jan 13, 2024
2 parents e37678d + fcccad2 commit fe3548c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 65 deletions.
48 changes: 24 additions & 24 deletions src/Fabulous/Array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ module ArraySlice =
// noop if we don't have enough space
if (used + by <= arr.Length) then
for i = used + by - 1 downto int by do
arr.[i] <- arr.[i - by]
arr[i] <- arr[i - by]

arr

module Array =
let inline appendOne (v: 'v) (arr: 'v array) =
let res = Array.zeroCreate(arr.Length + 1)
Array.blit arr 0 res 0 arr.Length
res.[arr.Length] <- v
res[arr.Length] <- v
res

/// This is insertion sort that is O(n*n) but it performs better
Expand All @@ -63,13 +63,13 @@ module Array =

for i in [ 1 .. N - 1 ] do
for j = i downto 1 do
let key = getKey attrs.[j]
let prevKey = getKey attrs.[j - 1]
let key = getKey attrs[j]
let prevKey = getKey attrs[j - 1]

if key < prevKey then
let temp = attrs.[j]
attrs.[j] <- attrs.[j - 1]
attrs.[j - 1] <- temp
let temp = attrs[j]
attrs[j] <- attrs[j - 1]
attrs[j - 1] <- temp

attrs

Expand Down Expand Up @@ -127,18 +127,18 @@ module StackAllocatedCollections =
let used =
match data.size % 3us with
| 0us -> // copy 3 items
arr.[size - 1] <- v2
arr.[size - 2] <- v1
arr.[size - 3] <- v0
arr[size - 1] <- v2
arr[size - 2] <- v1
arr[size - 3] <- v0
3
| 1us ->
// copy 1 item
arr.[size - 1] <- v0
arr[size - 1] <- v0
1
| 2us ->
// copy 2 item
arr.[size - 1] <- v1
arr.[size - 2] <- v0
arr[size - 1] <- v1
arr[size - 2] <- v0
2
| _ -> 0

Expand All @@ -149,9 +149,9 @@ module StackAllocatedCollections =
match leftToCopy with
| Empty -> i <- -1
| Filled((v0, v1, v2), before) ->
arr.[i] <- v2
arr.[i - 1] <- v1
arr.[i - 2] <- v0
arr[i] <- v2
arr[i - 1] <- v1
arr[i - 2] <- v0
i <- i - 3
leftToCopy <- before

Expand Down Expand Up @@ -305,7 +305,7 @@ module StackAllocatedCollections =
| 1 -> v1
| _ -> v2

| Many arr -> arr.[index]
| Many arr -> arr[index]


let find (test: 'v -> bool) (arr: StackArray3<'v> inref) : 'v =
Expand Down Expand Up @@ -417,7 +417,7 @@ module StackAllocatedCollections =
| Many struct (count, mutArr) ->
if mutArr.Length > (int count) then
// we can fit it in
mutArr.[int count] <- value
mutArr[int count] <- value
Many(count + 1us, mutArr)
else
// in this branch we reached the capacity of the array, thus needs to grow
Expand All @@ -430,7 +430,7 @@ module StackAllocatedCollections =
Array.zeroCreate(grow mutArr.Length)

Array.blit mutArr 0 res 0 mutArr.Length
res.[countInt] <- value
res[countInt] <- value
Many(count + 1us, res)

let inline toArray (arr: T<'v> inref) : 'v array =
Expand All @@ -442,7 +442,7 @@ module StackAllocatedCollections =
let inline fromArray (arr: 'v array) : T<'v> =
match arr.Length with
| 0 -> Empty
| 1 -> One arr.[0]
| 1 -> One arr[0]
| size -> Many(uint16 size, arr)

let inline toArraySlice (arr: T<'v> inref) : ArraySlice<'v> voption =
Expand Down Expand Up @@ -470,15 +470,15 @@ module StackAllocatedCollections =
if arr.Length >= (int used) + 1 then
// it means that arr can fit one more element
let arr = ArraySlice.shiftByMut &sliceB 1us
arr.[0] <- av
arr[0] <- av
Many(used + 1us, arr)
else
// we need to allocate a new one more
// Note very scientific formula of growth
let newArr = Array.zeroCreate(grow arr.Length)

Array.blit arr 0 newArr 1 (int used)
newArr.[0] <- av
newArr[0] <- av
Many(used + 1us, newArr)

| Many sliceA ->
Expand Down Expand Up @@ -633,7 +633,7 @@ module StackAllocatedCollections =
let encodedValue = ((uint16 op <<< 14) &&& opMask)
let encodedValue = encodedValue ||| (index &&& valueMask)

builder.ops.[builder.cursor] <- encodedValue
builder.ops[builder.cursor] <- encodedValue
builder.cursor <- builder.cursor + 1


Expand All @@ -655,6 +655,6 @@ module StackAllocatedCollections =
let res = Array.zeroCreate<'t> len

for i = 0 to len - 1 do
res.[i] <- map(decode builder.ops.[i])
res[i] <- map(decode builder.ops[i])

res
8 changes: 4 additions & 4 deletions src/Fabulous/AttributeDefinitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ module AttributeDefinitionStore =

let getScalar (key: ScalarAttributeKey) : ScalarAttributeData =
let index = ScalarAttributeKey.getKeyValue key
_scalars.[index]
_scalars[index]

let getSmallScalar (key: ScalarAttributeKey) : SmallScalarAttributeData =
let index = ScalarAttributeKey.getKeyValue key
_smallScalars.[index]
_smallScalars[index]

let getWidget (key: WidgetAttributeKey) : WidgetAttributeData = _widgets.[int key]
let getWidget (key: WidgetAttributeKey) : WidgetAttributeData = _widgets[int key]

let getWidgetCollection (key: WidgetCollectionAttributeKey) : WidgetCollectionAttributeData = _widgetCollections.[int key]
let getWidgetCollection (key: WidgetCollectionAttributeKey) : WidgetCollectionAttributeData = _widgetCollections[int key]

module AttributeHelpers =
open ScalarAttributeDefinitions
Expand Down
10 changes: 5 additions & 5 deletions src/Fabulous/Attributes.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Fabulous
namespace Fabulous

open System
open System.Runtime.CompilerServices
Expand Down Expand Up @@ -213,7 +213,7 @@ module Attributes =
for diff in diffs do
match diff with
| WidgetCollectionItemChange.Remove(index, widget) ->
let itemNode = node.TreeContext.GetViewNode(box targetColl.[index])
let itemNode = node.TreeContext.GetViewNode(box targetColl[index])

// Trigger the unmounted event
Dispatcher.dispatchEventForAllChildren itemNode widget Lifecycle.Unmounted
Expand All @@ -236,12 +236,12 @@ module Attributes =
Dispatcher.dispatchEventForAllChildren itemNode widget Lifecycle.Mounted

| WidgetCollectionItemChange.Update(index, widgetDiff) ->
let childNode = node.TreeContext.GetViewNode(box targetColl.[index])
let childNode = node.TreeContext.GetViewNode(box targetColl[index])

childNode.ApplyDiff(&widgetDiff)

| WidgetCollectionItemChange.Replace(index, oldWidget, newWidget) ->
let prevItemNode = node.TreeContext.GetViewNode(box targetColl.[index])
let prevItemNode = node.TreeContext.GetViewNode(box targetColl[index])

let struct (nextItemNode, view) = Helpers.createViewForWidget node newWidget

Expand All @@ -250,7 +250,7 @@ module Attributes =
prevItemNode.Disconnect()

// Replace the existing child in the UI tree at the index with the new one
targetColl.[index] <- unbox view
targetColl[index] <- unbox view

// Trigger the mounted event for the new child
Dispatcher.dispatchEventForAllChildren nextItemNode newWidget Lifecycle.Mounted
Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type WidgetBuilder<'msg, 'marker> =
| ValueSome attribs ->
let attribs2 = Array.zeroCreate(attribs.Length + 1)
Array.blit attribs 0 attribs2 0 attribs.Length
attribs2.[attribs.Length] <- attr
attribs2[attribs.Length] <- attr
attribs2

WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, ValueSome res, widgetCollectionAttributes))
Expand All @@ -110,7 +110,7 @@ type WidgetBuilder<'msg, 'marker> =
| ValueSome attribs ->
let attribs2 = Array.zeroCreate(attribs.Length + 1)
Array.blit attribs 0 attribs2 0 attribs.Length
attribs2.[attribs.Length] <- attr
attribs2[attribs.Length] <- attr
attribs2

WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, widgetAttributes, ValueSome res))
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous/Memo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Memo =

let inline private getMemoData (widget: Widget) : MemoData =
match widget.ScalarAttributes with
| ValueSome attrs when attrs.Length = 1 -> attrs.[0].Value :?> MemoData
| ValueSome attrs when attrs.Length = 1 -> attrs[0].Value :?> MemoData
| _ -> failwith "Memo widget cannot have extra attributes"

let internal canReuseMemoizedWidget prev next =
Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module StateStore =

let StateChanged = _stateChangedEvent.Publish

let get key = _states.[key]
let get key = _states[key]

let set key newState =
match _states.TryGetValue(key) with
| true, prevState when prevState = newState -> ()
| _ ->
_states.[key] <- newState
_states[key] <- newState
_stateChangedEvent.Trigger({ Key = key; NewState = newState })

let remove key = _states.Remove(key) |> ignore
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous/ViewNode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type ViewNode(parent: IViewNode option, treeContext: ViewTreeContext, targetRef:
member _.SetHandler<'T>(key: string, handlerOpt: 'T voption) =
match handlerOpt with
| ValueNone -> _handlers.Remove(key) |> ignore
| ValueSome v -> _handlers.[key] <- box v
| ValueSome v -> _handlers[key] <- box v

member _.Disconnect() = _isDisconnected <- true

Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous/WidgetDefinitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module WidgetDefinitionStore =

let mutable private _nextKey = 0

let get key = _widgets.[key]
let set key value = _widgets.[key] <- value
let get key = _widgets[key]
let set key value = _widgets[key] <- value

let getNextKey () : WidgetKey =
_widgets.Add(Unchecked.defaultof<WidgetDefinition>)
Expand Down
Loading

0 comments on commit fe3548c

Please sign in to comment.