Wrox Programmer Forums
|
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2011, 09:19 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Including NameTable Optimization (page 513)

Hi...

I don't know much about ASP.NET (yet), but I do know about polymorphism...
The code in listing 10-7 (and subsequent listings where the same technique is used), are not using the atomized strings...

From listing 10-7:

Code:
NameTable nt = new NameTable();
object book = nt.Add( "book" );
...
if ( ... && book.Equals( reader.LocalName ) )
The Add() method returns a string. So, the book variable, even though it's of type object, references a string object.
Since string overrides the Equals() method, the comparison will actually be a string comparison, and not an object reference comparison, as was intended. Polymorphism will cause the string override of Equals() to be called.

What the code should be in order to optimize it with the use of atomized strings is:
Code:
if ( ... && ReferenceEquals( book, reader.LocalName ) )
ReferenceEquals() is implemented by System.Object and compares the object references. book is a reference to the atomized string, so it will actually be compared to the atomized Reader.LocalName object reference.

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Python code optimization icopec Python 2 December 13th, 2011 05:13 AM
A little optimization puzzle williamlove Pro VB 6 2 October 18th, 2009 02:17 AM
Optimization akkad C# 5 November 1st, 2006 05:27 AM
Optimization of ASP page with VBScript anandham VBScript 0 April 18th, 2005 05:03 AM
Query optimization SubodhKumar SQL Language 1 October 22nd, 2003 06:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.