Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>how much receivers received the event</returns>
        public int Post(TContext ctx)
        {
            var receivers = ListPool <EventReceiver> .Request();

            receivers.AddRange(_receivers);
            var receviersToBeRemove = SetPool <int> .Request();

            try{
                var postIndex = 0;
                while (postIndex < receivers.Count)
                {
                    var receiver = receivers[postIndex];
                    receiver.action(ctx);
                    postIndex++;
                    if (receiver.type == CallbackType.Once)
                    {
                        receviersToBeRemove.Add(receiver.uniqueId);
                    }
                }
                return(receivers.Count);
            }finally{
                ListPool <EventReceiver> .Release(receivers);

                this.RemoveReceivers(receviersToBeRemove);
                SetPool <int> .Release(receviersToBeRemove);
            }
        }
Example #2
0
        public object SetPoolBorrowReturn()
        {
            var set = SetPool.Borrow <string>();

            SetPool.Return(set);
            return(set);
        }
Example #3
0
        public object NewSetPoolBorrowReturnUnionWithStrings()
        {
            var set = SetPool.Borrow <string>();

            set.UnionWith(Strings);
            SetPool.Return(set);
            return(set);
        }
Example #4
0
        private static void Handle(SyntaxNodeAnalysisContext context, IFieldSymbol assignedField)
        {
            if (context.IsExcludedFromAnalysis())
            {
                return;
            }

            if (IsInIgnoredScope(context))
            {
                return;
            }

            var typeDeclaration = context.Node.FirstAncestorOrSelf <TypeDeclarationSyntax>();
            var typeSymbol      = context.SemanticModel.GetDeclaredSymbolSafe(typeDeclaration, context.CancellationToken);

            if (!typeSymbol.Is(KnownSymbol.INotifyPropertyChanged))
            {
                return;
            }

            if (!typeSymbol.Equals(assignedField.ContainingType))
            {
                return;
            }

            var inProperty = context.Node.FirstAncestorOrSelf <PropertyDeclarationSyntax>();

            if (inProperty != null)
            {
                if (Property.IsSimplePropertyWithBackingField(inProperty, context.SemanticModel, context.CancellationToken))
                {
                    return;
                }
            }

            using (var pooledSet = SetPool <IPropertySymbol> .Create())
            {
                foreach (var member in typeDeclaration.Members)
                {
                    var propertyDeclaration = member as PropertyDeclarationSyntax;
                    if (propertyDeclaration == null ||
                        Property.IsLazy(propertyDeclaration, context.SemanticModel, context.CancellationToken))
                    {
                        continue;
                    }

                    var property = context.SemanticModel.GetDeclaredSymbolSafe(propertyDeclaration, context.CancellationToken);
                    var getter   = GetterBody(propertyDeclaration);
                    if (getter == null || property == null || property.DeclaredAccessibility != Accessibility.Public)
                    {
                        continue;
                    }

                    var accessor = context.Node.FirstAncestorOrSelf <AccessorDeclarationSyntax>();
                    if (accessor?.IsKind(SyntaxKind.GetAccessorDeclaration) == true &&
                        accessor.FirstAncestorOrSelf <PropertyDeclarationSyntax>() == propertyDeclaration)
                    {
                        continue;
                    }

                    var expressionBody = context.Node.FirstAncestorOrSelf <ArrowExpressionClauseSyntax>();
                    if (expressionBody?.FirstAncestorOrSelf <PropertyDeclarationSyntax>() == propertyDeclaration)
                    {
                        continue;
                    }

                    using (var pooled = TouchedFieldsWalker.Create(getter, context.SemanticModel, context.CancellationToken))
                    {
                        if (pooled.Item.Contains(assignedField))
                        {
                            if (PropertyChanged.InvokesPropertyChangedFor(context.Node, property, context.SemanticModel, context.CancellationToken) == AnalysisResult.No)
                            {
                                if (pooledSet.Item.Add(property))
                                {
                                    var properties = ImmutableDictionary.CreateRange(new[] { new KeyValuePair <string, string>(PropertyNameKey, property.Name), });
                                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties, property.Name));
                                }
                            }
                        }
                    }
                }
            }
        }
        private void UpdateViews()
        {
            var turnToVisibleItems = SetPool <int> .Request();

            try{
                if (_viewportDirty)
                {
                    InternalDebug("calculate item views visible");
                    if (_visibleItems == null)
                    {
                        _visibleItems = SetPool <int> .Request();
                    }
                    var newVisibleItems = SetPool <int> .Request();

                    this.layoutCalculator.GetOverlapsInViewport(_viewportRect, newVisibleItems);
                    var oldVisibleItems = _visibleItems;
                    try{
                        foreach (var index in oldVisibleItems)
                        {
                            if (!newVisibleItems.Contains(index))
                            {
                                //change to invisible
                                OnItemVisibleChanged(index, false);
                            }
                        }
                        foreach (var index in newVisibleItems)
                        {
                            if (!oldVisibleItems.Contains(index))
                            {
                                //change to visible
                                OnItemVisibleChanged(index, true);
                                turnToVisibleItems.Add(index);
                            }
                        }
                    }finally{
                        _visibleItems = newVisibleItems;
                        SetPool <int> .Release(oldVisibleItems);
                    }
                }

                if (_itemsDirty)
                {
                    foreach (var index in _visibleItems)
                    {
                        OnItemUpdate(index);
                    }
                }
                else
                {
                    foreach (var index in turnToVisibleItems)
                    {
                        OnItemUpdate(index);
                    }
                }

                if (_layoutDirty)
                {
                    InternalDebug("calculate item views layout");
                    foreach (var index in _visibleItems)
                    {
                        OnItemLayout(index);
                    }
                }
                else
                {
                    foreach (var index in turnToVisibleItems)
                    {
                        OnItemLayout(index);
                    }
                }
            }finally{
                _viewportDirty = false;
                _itemsDirty    = false;
                _layoutDirty   = false;
                SetPool <int> .Release(turnToVisibleItems);
            }
        }