From: Kim Phillips Date: Mon, 13 Aug 2012 16:34:44 -0500 Subject: [U-Boot] [u-boot-release] [PATCH 3/6] powerpc/85xx: introduce function serdes_device_from_fm_port() In-Reply-To: <50296FF9.8010407@freescale.com> References: <1344636096-11669-1-git-send-email-timur@freescale.com> <1344636096-11669-3-git-send-email-timur@freescale.com> <20120813161001.03e179cda8b406a3fcc93b3b@freescale.com> <50296FF9.8010407@freescale.com> Message-ID: <20120813163444.e109a97b75710257c5dd5183@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, 13 Aug 2012 16:22:01 -0500 Timur Tabi wrote: > Kim Phillips wrote: > > shouldn't this be a static const array lookup? > > The compiler should convert it into an array lookup automatically, but I > can change it if you insist. Since I don't like writing code that depends > on the values of an enum, the array will look like this: > > static const enum srds_prtcl srds_table[] = { > [FM1_DTSEC1] = SGMII_FM1_DTSEC1, > [FM1_DTSEC2] = SGMII_FM1_DTSEC2, > [FM1_DTSEC3] = SGMII_FM1_DTSEC3, > [FM1_DTSEC4] = SGMII_FM1_DTSEC4, > [FM1_DTSEC5] = SGMII_FM1_DTSEC5, > [FM1_10GEC1] = XAUI_FM1, > [FM2_DTSEC1] = SGMII_FM2_DTSEC1, > [FM2_DTSEC2] = SGMII_FM2_DTSEC2, > [FM2_DTSEC3] = SGMII_FM2_DTSEC3, > [FM2_DTSEC4] = SGMII_FM2_DTSEC4, > [FM2_DTSEC5] = SGMII_FM2_DTSEC5, > [FM2_10GEC1] = XAUI_FM2, > }; > > if ((port < FM1_DTSEC1) || (port > FM2_10GEC1)) > return NONE; > else > return srds_table[port]; > > I'm not sure that's an improvement. it's ~30% less lines of code, and the maps lie on the same line, which helps when grepping. Kim