Return-Path: X-Original-To: apmail-flex-issues-archive@minotaur.apache.org Delivered-To: apmail-flex-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8D0D9180CA for ; Fri, 11 Dec 2015 06:12:11 +0000 (UTC) Received: (qmail 9145 invoked by uid 500); 11 Dec 2015 06:12:11 -0000 Delivered-To: apmail-flex-issues-archive@flex.apache.org Received: (qmail 9071 invoked by uid 500); 11 Dec 2015 06:12:11 -0000 Mailing-List: contact issues-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list issues@flex.apache.org Received: (qmail 9045 invoked by uid 99); 11 Dec 2015 06:12:11 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Dec 2015 06:12:11 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 15B862C1F62 for ; Fri, 11 Dec 2015 06:12:11 +0000 (UTC) Date: Fri, 11 Dec 2015 06:12:11 +0000 (UTC) From: "Andy Dufilie (JIRA)" To: issues@flex.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (FLEX-34984) for-each loops cross-compile incorrectly MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FLEX-34984?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Andy Dufilie updated FLEX-34984: -------------------------------- Description: When you write a for-each loop, the iterable gets re-evaluated on every iteration. Example code: {code} for each (var item:Object in Test.getItems()) { Test.doSomething(item); } {code} Cross-compiled: {code} for (var foreachiter0 in Test.getItems()) { var item = Test.getItems()[foreachiter0]; { Test.doSomething(item); }} {code} It should not call Test.getItems() on every loop iteration. Instead, it should generate a new local variable prior to entering the loop to store the result. I believe the offending code is reduce_forLoop() in JSGeneratingReducer.java: https://github.com/apache/flex-falcon/blob/808fd1601a0228883b06d061d0f6bd101888284e/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java#L3426 was: When you write a for-each loop, the iterable gets re-evaluated on every iteration. Example code: {code} for each (var item:Object in Test.getItems()) { Test.doSomething(item); } {code} Cross-compiled: {code} for (var foreachiter0 in Test.getItems()) { var item = Test.getItems()[foreachiter0]; { Test.doSomething(item); }} {code} It should not call Test.getItems() on every loop iteration. Instead, it should generate a new local variable prior to entering the loop to store the result. I believe the offending code is reduce_forLoop() in JSGeneratingReducer.java: https://github.com/apache/flex-falcon/blob/808fd1601a0228883b06d061d0f6bd101888284e/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java#L3426 > for-each loops cross-compile incorrectly > ---------------------------------------- > > Key: FLEX-34984 > URL: https://issues.apache.org/jira/browse/FLEX-34984 > Project: Apache Flex > Issue Type: Bug > Components: Falcon, FlexJS > Affects Versions: Apache FlexJS 0.5.0 > Reporter: Andy Dufilie > > When you write a for-each loop, the iterable gets re-evaluated on every iteration. > Example code: > {code} > for each (var item:Object in Test.getItems()) { > Test.doSomething(item); > } > {code} > Cross-compiled: > {code} > for (var foreachiter0 in Test.getItems()) > { > var item = Test.getItems()[foreachiter0]; > { > Test.doSomething(item); > }} > {code} > It should not call Test.getItems() on every loop iteration. Instead, it should generate a new local variable prior to entering the loop to store the result. > I believe the offending code is reduce_forLoop() in JSGeneratingReducer.java: > https://github.com/apache/flex-falcon/blob/808fd1601a0228883b06d061d0f6bd101888284e/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java#L3426 -- This message was sent by Atlassian JIRA (v6.3.4#6332)